Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var overallTestStartTime = Date.now(); | 5 var overallTestStartTime = Date.now(); |
| 6 var kUseIndex = true; | 6 var kUseIndex = true; |
| 7 var kDontUseIndex = false; | 7 var kDontUseIndex = false; |
| 8 var kReadKeysOnly = true; | 8 var kReadKeysOnly = true; |
| 9 var kReadDataToo = false; | 9 var kReadDataToo = false; |
| 10 var kWriteToo = true; | 10 var kWriteToo = true; |
| 11 var kDontWrite = false; | 11 var kDontWrite = false; |
| 12 var kWriteSameStore = true; | |
| 13 var kWriteDifferentStore = false; | |
| 14 var kPlaceholderArg = false; | |
| 12 | 15 |
| 13 var tests = [ | 16 var tests = [ |
| 17 /* These tests give crazy results, and the fourth times out. | |
| 18 * See crbug.com/140123. | |
| 19 | |
| 20 // Create a few small items in a single object store, then delete everything. | |
| 21 [testCreateAndDeleteDatabase, 4, 1, 1], | |
| 22 // Create a few small items in a single object store, then delete everything. | |
| 23 [testCreateAndDeleteDatabase, 3, 1, 1], | |
| 24 // Create a couple small items in a single object store, then delete everything. | |
| 25 [testCreateAndDeleteDatabase, 2, 1, 1], | |
| 26 // Create a single small items in a single object store, then delete everything. | |
| 27 [testCreateAndDeleteDatabase, 1, 1, 1], | |
| 28 */ | |
| 14 // Create a single small item in a single object store. | 29 // Create a single small item in a single object store. |
| 15 [testCreateKeysInStores, 1, 1, 1], | 30 [testCreateKeysInStores, 1, 1, 1], |
| 16 // Create many small items in a single object store. | 31 // Create many small items in a single object store. |
| 17 [testCreateKeysInStores, 100, 1, 1], | 32 [testCreateKeysInStores, 100, 1, 1], |
| 18 // Create a single small item in many object stores. | 33 // Create a single small item in many object stores. |
| 19 [testCreateKeysInStores, 1, 100, 1], | 34 [testCreateKeysInStores, 1, 100, 1], |
| 20 // Create many large items in a single object store. | 35 // Create many large items in a single object store. |
| 21 [testCreateKeysInStores, 100, 1, 10000], | 36 [testCreateKeysInStores, 100, 1, 10000], |
| 22 // Read a few random items in each of many transactions. | 37 // Read a few random items in each of many transactions. |
| 23 [testRandomReadsAndWrites, 1000, 5, 0, 50, kDontUseIndex], | 38 [testRandomReadsAndWrites, 1000, 5, 0, 50, kDontUseIndex], |
| 24 // Read many random items in each of a few transactions. | 39 // Read many random items in each of a few transactions. |
| 25 [testRandomReadsAndWrites, 1000, 50, 0, 5, kDontUseIndex], | 40 [testRandomReadsAndWrites, 1000, 50, 0, 5, kDontUseIndex], |
| 26 // Read many random items in each of a few transactions, in a large store. | 41 // Read many random items in each of a few transactions, in a large store. |
| 27 [testRandomReadsAndWrites, 5000, 50, 0, 5, kDontUseIndex], | 42 [testRandomReadsAndWrites, 5000, 50, 0, 5, kDontUseIndex], |
| 28 // Read a few random items from an index, in each of many transactions. | 43 // Read a few random items from an index, in each of many transactions. |
| 29 [testRandomReadsAndWrites, 1000, 5, 0, 50, kUseIndex], | 44 [testRandomReadsAndWrites, 1000, 5, 0, 50, kUseIndex], |
| 30 // Read many random items from an index, in each of a few transactions. | 45 // Read many random items from an index, in each of a few transactions. |
| 31 [testRandomReadsAndWrites, 1000, 50, 0, 5, kUseIndex], | 46 [testRandomReadsAndWrites, 1000, 50, 0, 5, kUseIndex], |
| 32 // Read many random items from an index, in each of a few transactions, in a | 47 // Read many random items from an index, in each of a few transactions, in a |
| 33 // large store. | 48 // large store. |
| 34 [testRandomReadsAndWrites, 5000, 50, 0, 5, kUseIndex], | 49 [testRandomReadsAndWrites, 5000, 50, 0, 5, kUseIndex], |
| 35 // Read and write a few random items in each of many transactions. | 50 // Read and write a few random items in each of many transactions. |
| 36 [testRandomReadsAndWrites, 1000, 5, 5, 50, kDontUseIndex], | 51 [testRandomReadsAndWrites, 1000, 5, 5, 50, kDontUseIndex], |
| 37 // Read and write a few random items, reading from an index, in each of many | 52 // Read and write a few random items, reading from an index, in each of many |
| 38 // transactions. | 53 // transactions. |
| 39 [testRandomReadsAndWrites, 1000, 5, 5, 50, kUseIndex], | 54 [testRandomReadsAndWrites, 1000, 5, 5, 50, kUseIndex], |
| 40 // Read a long, contiguous sequence of an object store via a cursor. | 55 // Read a long, contiguous sequence of an object store via a cursor. |
| 41 [testCursorReadsAndRandomWrites, kReadDataToo, kDontUseIndex, kDontWrite], | 56 [testCursorReadsAndRandomWrites, kReadDataToo, kDontUseIndex, kDontWrite, |
| 57 kPlaceholderArg], | |
| 42 // Read a sequence of an object store via a cursor, writing | 58 // Read a sequence of an object store via a cursor, writing |
| 43 // transformed values into another. | 59 // transformed values into another. |
| 44 [testCursorReadsAndRandomWrites, kReadDataToo, kDontUseIndex, kWriteToo], | 60 [testCursorReadsAndRandomWrites, kReadDataToo, kDontUseIndex, kWriteToo, |
| 61 kWriteDifferentStore], | |
| 62 // Read a sequence of an object store via a cursor, writing | |
| 63 // transformed values into another. | |
| 64 [testCursorReadsAndRandomWrites, kReadDataToo, kDontUseIndex, kWriteToo, | |
| 65 kWriteSameStore], | |
| 45 // Read a sequence of an index into an object store via a cursor. | 66 // Read a sequence of an index into an object store via a cursor. |
| 46 [testCursorReadsAndRandomWrites, kReadDataToo, kUseIndex, kDontWrite], | 67 [testCursorReadsAndRandomWrites, kReadDataToo, kUseIndex, kDontWrite, |
| 68 kPlaceholderArg], | |
| 47 // Read a sequence of an index into an object store via a key cursor. | 69 // Read a sequence of an index into an object store via a key cursor. |
| 48 [testCursorReadsAndRandomWrites, kReadKeysOnly, kUseIndex, kDontWrite], | 70 [testCursorReadsAndRandomWrites, kReadKeysOnly, kUseIndex, kDontWrite, |
| 71 kPlaceholderArg], | |
| 49 // Make batches of random writes into a store, triggered by periodic setTimeout | 72 // Make batches of random writes into a store, triggered by periodic setTimeout |
| 50 // calls. | 73 // calls. |
| 51 [testSporadicWrites, 5, 0], | 74 [testSporadicWrites, 5, 0], |
| 52 // Make large batches of random writes into a store, triggered by periodic | 75 // Make large batches of random writes into a store, triggered by periodic |
| 53 // setTimeout calls. | 76 // setTimeout calls. |
| 54 [testSporadicWrites, 50, 0], | 77 [testSporadicWrites, 50, 0], |
| 55 // Make batches of random writes into a store with many indices, triggered by | 78 // Make batches of random writes into a store with many indices, triggered by |
| 56 // periodic setTimeout calls. | 79 // periodic setTimeout calls. |
| 57 [testSporadicWrites, 5, 10], | 80 [testSporadicWrites, 5, 10], |
| 58 // Make large batches of random writes into a store with many indices, triggered | 81 // Make large batches of random writes into a store with many indices, triggered |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 79 onAllTestsComplete(); | 102 onAllTestsComplete(); |
| 80 } | 103 } |
| 81 } | 104 } |
| 82 | 105 |
| 83 function onAllTestsComplete() { | 106 function onAllTestsComplete() { |
| 84 var overallDuration = Date.now() - overallTestStartTime; | 107 var overallDuration = Date.now() - overallTestStartTime; |
| 85 automation.addResult("OverallTestDuration", overallDuration); | 108 automation.addResult("OverallTestDuration", overallDuration); |
| 86 automation.setDone(); | 109 automation.setDone(); |
| 87 } | 110 } |
| 88 | 111 |
| 112 function testCreateAndDeleteDatabase( | |
| 113 numKeys, numStores, payloadLength, onTestComplete) { | |
| 114 var testName = getDisplayName(arguments); | |
| 115 assert(numKeys >= 0); | |
| 116 assert(numStores >= 1); | |
| 117 var objectStoreNames = []; | |
| 118 for (var i=0; i < numStores; ++i) { | |
| 119 objectStoreNames.push("store " + i); | |
| 120 } | |
| 121 var value = stringOfLength(payloadLength); | |
| 122 function getValue() { | |
| 123 return value; | |
| 124 } | |
| 125 | |
| 126 automation.setStatus("Creating database."); | |
| 127 var startTime = Date.now(); | |
| 128 | |
| 129 createDatabase(testName, objectStoreNames, onCreated, onError); | |
| 130 | |
| 131 function onCreated(db) { | |
| 132 automation.setStatus("Constructing transaction."); | |
| 133 var transaction = | |
| 134 getTransaction(db, objectStoreNames, "readwrite", onValuesWritten); | |
| 135 putLinearValues(transaction, objectStoreNames, numKeys, null, getValue); | |
| 136 } | |
| 137 | |
| 138 function onValuesWritten() { | |
| 139 automation.setStatus("Deleting database."); | |
| 140 deleteDatabase(testName, onDeleted); | |
|
jsbell
2012/08/01 23:05:26
Need to call db.close() before deleteDatabase() or
ericu
2012/08/01 23:39:43
Added onblocked.
| |
| 141 } | |
| 142 | |
| 143 function onDeleted() { | |
| 144 var duration = Date.now() - startTime; | |
| 145 automation.addResult(testName, duration); | |
| 146 automation.setStatus("Deleted database."); | |
| 147 onTestComplete(); | |
| 148 } | |
| 149 } | |
| 150 | |
| 89 function testCreateKeysInStores( | 151 function testCreateKeysInStores( |
| 90 numKeys, numStores, payloadLength, onTestComplete) { | 152 numKeys, numStores, payloadLength, onTestComplete) { |
| 91 var testName = getDisplayName(arguments); | 153 var testName = getDisplayName(arguments); |
| 92 assert(numKeys >= 0); | 154 assert(numKeys >= 0); |
| 93 assert(numStores >= 1); | 155 assert(numStores >= 1); |
| 94 var objectStoreNames = []; | 156 var objectStoreNames = []; |
| 95 for (var i=0; i < numStores; ++i) { | 157 for (var i=0; i < numStores; ++i) { |
| 96 objectStoreNames.push("store " + i); | 158 objectStoreNames.push("store " + i); |
| 97 } | 159 } |
| 98 var value = stringOfLength(payloadLength); | 160 var value = stringOfLength(payloadLength); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 completionFunc = getCompletionFunc("testDeleteIndex", | 277 completionFunc = getCompletionFunc("testDeleteIndex", |
| 216 indexCreationCompleteTime, onTestComplete); | 278 indexCreationCompleteTime, onTestComplete); |
| 217 var f = function(objectStore) { | 279 var f = function(objectStore) { |
| 218 objectStore.deleteIndex("index"); | 280 objectStore.deleteIndex("index"); |
| 219 }; | 281 }; |
| 220 automation.setStatus("Deleting index."); | 282 automation.setStatus("Deleting index."); |
| 221 alterObjectStores(testName, objectStoreNames, f, completionFunc, onError); | 283 alterObjectStores(testName, objectStoreNames, f, completionFunc, onError); |
| 222 } | 284 } |
| 223 } | 285 } |
| 224 | 286 |
| 225 // TODO: Add a version that writes back to the same store, to see how that | |
| 226 // affects cursor speed w.r.t. invalidated caches. | |
| 227 function testCursorReadsAndRandomWrites( | 287 function testCursorReadsAndRandomWrites( |
| 228 readKeysOnly, useIndexForReads, writeToAnotherStore, onTestComplete) { | 288 readKeysOnly, useIndexForReads, writeAlso, sameStoreForWrites, |
| 289 onTestComplete) { | |
| 229 // There's no key cursor unless you're reading from an index. | 290 // There's no key cursor unless you're reading from an index. |
| 230 assert(useIndexForReads || !readKeysOnly); | 291 assert(useIndexForReads || !readKeysOnly); |
| 231 // If we're writing to another store, having an index would constrain our | 292 // If we're writing to another store, having an index would constrain our |
| 232 // writes, as we create both object stores with the same configurations. | 293 // writes, as we create both object stores with the same configurations. |
| 233 // We could do that if needed, but it's simpler not to. | 294 // We could do that if needed, but it's simpler not to. |
| 234 assert(!useIndexForReads || !writeToAnotherStore); | 295 assert(!useIndexForReads || !writeAlso); |
| 235 var numKeys = 1000; | 296 var numKeys = 1000; |
| 236 var numReadsPerTransaction = 100; | 297 var numReadsPerTransaction = 100; |
| 237 var testName = getDisplayName(arguments); | 298 var testName = getDisplayName(arguments); |
| 238 var objectStoreNames = ["input store"]; | 299 var objectStoreNames = ["input store"]; |
| 239 if (writeToAnotherStore) | 300 var outputStoreName; |
| 240 objectStoreNames.push("output store"); | 301 if (writeAlso) { |
| 302 if (sameStoreForWrites) { | |
| 303 outputStoreName = objectStoreNames[0]; | |
| 304 } else { | |
| 305 outputStoreName = "output store"; | |
| 306 objectStoreNames.push(outputStoreName); | |
| 307 } | |
| 308 } | |
| 241 var getKeyForRead = getSimpleKey; | 309 var getKeyForRead = getSimpleKey; |
| 242 var indexName; | 310 var indexName; |
| 243 if (useIndexForReads) { | 311 if (useIndexForReads) { |
| 244 indexName = "index"; | 312 indexName = "index"; |
| 245 getKeyForRead = function(i) { | 313 getKeyForRead = function(i) { |
| 246 // This depends on the implementations of getValuesFromCursor and | 314 // This depends on the implementations of getValuesFromCursor and |
| 247 // getObjectValue. We reverse the order of the iteration here so that | 315 // getObjectValue. We reverse the order of the iteration here so that |
| 248 // setting up bounds from k to k+n with n>0 works. Without this reversal, | 316 // setting up bounds from k to k+n with n>0 works. Without this reversal, |
| 249 // the upper bound is below the lower bound. | 317 // the upper bound is below the lower bound. |
| 250 return getBackwardIndexKey(numKeys - i); | 318 return getBackwardIndexKey(numKeys - i); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 268 var transaction = getTransaction(db, objectStoreNames, "readwrite", | 336 var transaction = getTransaction(db, objectStoreNames, "readwrite", |
| 269 function() { onSetupComplete(db); }); | 337 function() { onSetupComplete(db); }); |
| 270 putLinearValues(transaction, objectStoreNames, numKeys, getSimpleKey, | 338 putLinearValues(transaction, objectStoreNames, numKeys, getSimpleKey, |
| 271 getObjectValue); | 339 getObjectValue); |
| 272 } | 340 } |
| 273 function onSetupComplete(db) { | 341 function onSetupComplete(db) { |
| 274 automation.setStatus("Setup complete."); | 342 automation.setStatus("Setup complete."); |
| 275 var completionFunc = | 343 var completionFunc = |
| 276 getCompletionFunc(testName, Date.now(), onTestComplete); | 344 getCompletionFunc(testName, Date.now(), onTestComplete); |
| 277 var mode = "readonly"; | 345 var mode = "readonly"; |
| 278 if (writeToAnotherStore) | 346 if (writeAlso) |
| 279 mode = "readwrite"; | 347 mode = "readwrite"; |
| 280 var transaction = | 348 var transaction = |
| 281 getTransaction(db, objectStoreNames, mode, completionFunc); | 349 getTransaction(db, objectStoreNames, mode, completionFunc); |
| 282 | 350 |
| 283 getValuesFromCursor( | 351 getValuesFromCursor( |
| 284 transaction, objectStoreNames[0], numReadsPerTransaction, numKeys, | 352 transaction, objectStoreNames[0], numReadsPerTransaction, numKeys, |
| 285 indexName, getKeyForRead, readKeysOnly, objectStoreNames[1]); | 353 indexName, getKeyForRead, readKeysOnly, outputStoreName); |
| 286 } | 354 } |
| 287 } | 355 } |
| 288 | 356 |
| 289 function testSporadicWrites( | 357 function testSporadicWrites( |
| 290 numWritesPerTransaction, numIndices, onTestComplete) { | 358 numWritesPerTransaction, numIndices, onTestComplete) { |
| 291 var numKeys = 1000; | 359 var numKeys = 1000; |
| 292 // With 30 transactions, spaced 50ms apart, we'll need at least 1.5s. | 360 // With 30 transactions, spaced 50ms apart, we'll need at least 1.5s. |
| 293 var numTransactions = 30; | 361 var numTransactions = 30; |
| 294 var delayBetweenBatches = 50; | 362 var delayBetweenBatches = 50; |
| 295 var indexName; | 363 var indexName; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 | 411 |
| 344 var mode = "readonly"; | 412 var mode = "readonly"; |
| 345 if (numWritesPerTransaction) | 413 if (numWritesPerTransaction) |
| 346 mode = "readwrite"; | 414 mode = "readwrite"; |
| 347 | 415 |
| 348 var transaction = getTransaction(db, objectStoreNames, mode, batchComplete); | 416 var transaction = getTransaction(db, objectStoreNames, mode, batchComplete); |
| 349 putRandomValues(transaction, objectStoreNames, numWritesPerTransaction, | 417 putRandomValues(transaction, objectStoreNames, numWritesPerTransaction, |
| 350 numKeys); | 418 numKeys); |
| 351 } | 419 } |
| 352 } | 420 } |
| OLD | NEW |