test_file_repeated_add_delete.html (2841B)
1 <!-- 2 Any copyright is dedicated to the Public Domain. 3 http://creativecommons.org/publicdomain/zero/1.0/ 4 --> 5 <html> 6 <head> 7 <title>Indexed Database Blob Add/Delete Stress Test</title> 8 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 11 12 <script type="text/javascript"> 13 /* 14 * This is a stress test which rapidly adds and deletes blobs in a row in 15 * separate transactions. Internally, blobs are only removed when all memory 16 * and database references drop to zero. At that point an asynchronous 17 * delete operation is scheduled which removes the backing file from disk. 18 * So the overall behavior and timing depends on cycle collection and 19 * garbage collection. The main goal of this test is to make it more likely 20 * that internal structures are accessed by multiple threads at the same 21 * time, potentially discovering races or other issues. 22 * 23 * Note that the test needs to always create a new blob and a new 24 * transaction, otherwise new backing files wouldn't be created due to 25 * internal optimizations for de-duplication. 26 */ 27 function* testSteps() 28 { 29 const READ_WRITE = "readwrite"; 30 31 const name = window.location.pathname; 32 33 const objectStoreName = "Blobs"; 34 35 { 36 const request = indexedDB.open(name, 1); 37 request.onerror = errorHandler; 38 request.onupgradeneeded = grabEventAndContinueHandler; 39 request.onsuccess = grabEventAndContinueHandler; 40 } 41 42 { 43 const event = yield undefined; 44 45 is(event.type, "upgradeneeded", "Got correct event type"); 46 47 const db = event.target.result; 48 db.onerror = errorHandler; 49 50 const objectStore = db.createObjectStore(objectStoreName, {}); 51 52 objectStore.add(getRandomBlob(1), 1); 53 } 54 55 { 56 const event = yield undefined; 57 58 is(event.type, "success", "Got correct event type"); 59 60 const db = event.target.result; 61 db.onerror = errorHandler; 62 63 let index = 1; 64 65 function doWork() { 66 const transaction = db.transaction([objectStoreName], READ_WRITE); 67 68 const objectStore = transaction.objectStore(objectStoreName); 69 70 const deleteRequest = objectStore.delete(index); 71 deleteRequest.onsuccess = function () { 72 index++; 73 74 const addRequest = objectStore.add(getRandomBlob(1), index); 75 addRequest.onsuccess = function () { 76 if (index < 1000) { 77 doWork(); 78 } else { 79 continueToNextStep(); 80 } 81 }; 82 }; 83 } 84 85 doWork(); 86 87 yield undefined; 88 } 89 90 finishTest(); 91 } 92 </script> 93 <script type="text/javascript" src="file.js"></script> 94 <script type="text/javascript" src="helpers.js"></script> 95 96 </head> 97 98 <body onload="runTest();"></body> 99 100 </html>