database-threading-stress-test.html 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <style>
  5. pre { padding: 5px; border: 1px solid black; }
  6. </style>
  7. <script>
  8. var db;
  9. try {
  10. if (window.openDatabase) {
  11. db = openDatabase("StressTest1", "1.0", "Database Stress Test", 200000);
  12. if (!db)
  13. alert("Failed to open the database on disk. This is probably because the version was bad or there is not enough space left in this domain's quota");
  14. } else
  15. alert("Couldn't open the database.");
  16. } catch(err) { }
  17. var highestId = 0;
  18. var allData = new Array();
  19. function newData()
  20. {
  21. var id = ++highestId;
  22. allData.push(id);
  23. db.transaction(function (tx)
  24. {
  25. tx.executeSql("INSERT INTO FillerData (id, filler) VALUES (?, randomblob(1024))", [id]);
  26. });
  27. }
  28. function testOpen()
  29. {
  30. for (var i = 0; i < 4; i++) {
  31. newData();
  32. }
  33. setTimeout("testClose();", 0);
  34. }
  35. function testClose()
  36. {
  37. db.transaction(function(tx)
  38. {
  39. for (var i = 0; i < allData.length; i++)
  40. tx.executeSql("DELETE FROM FillerData WHERE id = ?", [allData[i]]);
  41. allData = new Array();
  42. });
  43. setTimeout("testOpen();", 0);
  44. }
  45. function updateTransactionCount()
  46. {
  47. document.getElementById("transactionCount").innerHTML = "Current Transaction Count: " + highestId;
  48. setTimeout("updateTransactionCount();", 1000);
  49. }
  50. function loaded()
  51. {
  52. db.transaction(function(tx) {
  53. tx.executeSql("SELECT COUNT(*) FROM FillerData", [], function(result) { }, function(tx, error) {
  54. tx.executeSql("CREATE TABLE FillerData (id REAL UNIQUE, filler)", [], function(result) {
  55. });
  56. });
  57. });
  58. setTimeout("testOpen();", 0);
  59. setTimeout("updateTransactionCount();", 1000);
  60. }
  61. addEventListener('load', loaded, false);
  62. </script>
  63. </head>
  64. <body>
  65. This test stresses the database threading code by constantly opening transactions to the test database at a fast rate.<br>
  66. See radar 5729446 for more details.<br>
  67. <pre id="transactionCount">Current Transaction Count: 0</pre>
  68. </body>
  69. </html>