1 function terminateTest()
4 testRunner
.notifyDone();
7 function openTestDatabase()
9 return openDatabaseWithSuffix("ReadAndWriteTransactionsDontRunTogetherTest",
11 "Test to make sure that read and write transactions on different DB handles to the same DB don't run at the same time.",
15 var readTransactionsInProgress
= 0;
16 var writeTransactionsInProgress
= 0;
17 var totalTransactions
= 0;
18 var finishedTransactions
= 0;
20 function runTransaction(db
, readOnly
)
22 var transactionFunction
= (readOnly
? db
.readTransaction
: db
.transaction
);
23 transactionFunction
.call(db
, function(tx
) {
25 if (writeTransactionsInProgress
!= 0) {
26 log("Read transaction starting while write transaction in progress.");
29 readTransactionsInProgress
++;
31 if ((readTransactionsInProgress
!= 0) || (writeTransactionsInProgress
!= 0)) {
32 log("Write transaction starting while another transaction in progress.");
35 writeTransactionsInProgress
++;
37 tx
.executeSql("SELECT * FROM Test;");
39 log((readOnly
? "Read" : "Write") + " transaction failed: " + error
.message
);
42 finishedTransactions
++;
44 readTransactionsInProgress
--;
46 writeTransactionsInProgress
--;
47 log("Transaction successful.");
48 if ((finishedTransactions
== totalTransactions
) && (readTransactionsInProgress
== 0) && (writeTransactionsInProgress
== 0))
53 function runReadAndWriteTransactions(db1
, db2
, db3
)
55 totalTransactions
= 10;
56 finishedTransactions
= 0;
57 runTransaction(db1
, true);
58 runTransaction(db2
, true);
59 runTransaction(db1
, false);
60 runTransaction(db1
, true);
61 runTransaction(db2
, true);
62 runTransaction(db3
, true);
63 runTransaction(db1
, false);
64 runTransaction(db2
, false);
65 runTransaction(db1
, true);
66 runTransaction(db3
, true);
70 var db1
= openTestDatabase();
71 var db2
= openTestDatabase();
72 var db3
= openTestDatabase();
73 db1
.transaction(function(tx
) {
74 tx
.executeSql("CREATE TABLE IF NOT EXISTS Test (Foo int);");
76 log("Cannot create the Test table: " + error
.message
);
79 runReadAndWriteTransactions(db1
, db2
, db3
);