summaryrefslogtreecommitdiffstats
path: root/LayoutTests/storage/open-database-while-transaction-in-progress.html
blob: 691f6fefa0f745a0a2969c3a3f88ed9f4a8acc0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<html>
<head>
<script>

function log(message)
{
    document.body.innerHTML += message + "<br>";
}

var complete = 0;

function checkCompletion()
{
    // The test should end after two transactions
    if (++complete == 1 && window.layoutTestController)
        layoutTestController.notifyDone();
}

// Opens the database used in this test case
function openTestDatabase()
{
    return openDatabase("OpenDatabaseWhileTransactionInProgressTest",
                        "1.0",
                        "Test to make sure that calling openDatabase() while a transaction is in progress on a different handle to the same database does not result in a deadlock.",
                        2100000); // 2MB + epsilon
}

// See https://bugs.webkit.org/show_bug.cgi?id=28207
// In order to trigger this bug, the transaction must acquire an exclusive
// lock on the DB file before trying to obtain a second handle to the same DB.
// The only way to force SQLite to obtain an exclusive lock is to change more
// than cache_size * page_size bytes in the database. The default value for
// cache_size is 2000 pages, and the default page_size is 1024 bytes. So the
// size of the blob must be at least 2MB.
function runTest()
{
    if (window.layoutTestController) {
        layoutTestController.dumpAsText();
        layoutTestController.waitUntilDone();
    }

    try {
        var db1 = openTestDatabase();
        db1.transaction(function(tx) {
            // Create the Test table if it does not exist
            tx.executeSql("CREATE TABLE IF NOT EXISTS Test (Foo BLOB);");
            tx.executeSql("INSERT INTO Test VALUES (ZEROBLOB(2097152));", [],
                          function(result) {
                              var db2 = openTestDatabase();
                              log("openDatabase() succeeded.");
                          },
                          function(tx, error) {
                              log("Executing statement failed: " + error.message);
                          });

            // Clean up the DB to allow for repeated runs of this test
            // without needing to increase the default allowed quota (5MB)
            tx.executeSql("DELETE FROM Test;");
        }, function(error) {
            log("Transaction failed: " + error.message);
        }, function() {
            checkCompletion();
        });
    } catch(err) {}
}
</script>
</head>
<body onload="runTest();">
This is a test to see if opening a database while a transaction is running on a different handle to the same database results in a deadlock.<br>
</body>
</html>