gecko/dom/indexedDB/test/test_writer_starvation.html
Ben Turner bfa7cae37b Bug 765839 - 'Enable IndexedDB OOP test suite'. r=khuey.
--HG--
extra : transplant_source : %3Bb4%A4%99fC%9Cg%86%9B%1F3%C6%0F%01T%1C%3C%AE
2012-06-19 18:50:39 -07:00

111 lines
3.6 KiB
HTML

<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<html>
<head>
<title>Indexed Database Property Test</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="text/javascript;version=1.7">
function testSteps()
{
const name = window.location.pathname;
// Needs to be enough to saturate the thread pool.
const SYNC_REQUEST_COUNT = 25;
let request = mozIndexedDB.open(name, 1);
request.onerror = errorHandler;
request.onupgradeneeded = grabEventAndContinueHandler;
request.onsuccess = grabEventAndContinueHandler;
let event = yield;
let db = event.target.result;
db.onerror = errorHandler;
is(event.target.transaction.mode, "versionchange", "Correct mode");
let objectStore = db.createObjectStore("foo", { autoIncrement: true });
request = objectStore.add({});
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
let key = event.target.result;
ok(key, "Got a key");
yield;
let continueReading = true;
let readerCount = 0;
let writerCount = 0;
let callbackCount = 0;
// Generate a bunch of reads right away without returning to the event
// loop.
info("Generating " + SYNC_REQUEST_COUNT + " readonly requests");
for (let i = 0; i < SYNC_REQUEST_COUNT; i++) {
readerCount++;
let request = db.transaction("foo").objectStore("foo").get(key);
request.onsuccess = function(event) {
is(event.target.transaction.mode, "readonly", "Correct mode");
callbackCount++;
};
}
while (continueReading) {
readerCount++;
info("Generating additional readonly request (" + readerCount + ")");
let request = db.transaction("foo").objectStore("foo").get(key);
request.onsuccess = function(event) {
callbackCount++;
info("Received readonly request callback (" + callbackCount + ")");
is(event.target.transaction.mode, "readonly", "Correct mode");
if (callbackCount == SYNC_REQUEST_COUNT) {
writerCount++;
info("Generating 1 readwrite request with " + readerCount +
" previous readonly requests");
let request = db.transaction("foo", "readwrite")
.objectStore("foo")
.add({}, readerCount);
request.onsuccess = function(event) {
callbackCount++;
info("Received readwrite request callback (" + callbackCount + ")");
is(event.target.transaction.mode, "readwrite", "Correct mode");
is(event.target.result, callbackCount,
"write callback came before later reads");
}
}
else if (callbackCount == SYNC_REQUEST_COUNT + 5) {
continueReading = false;
}
};
setTimeout(function() { testGenerator.next(); }, writerCount ? 1000 : 100);
yield;
}
while (callbackCount < (readerCount + writerCount)) {
executeSoon(function() { testGenerator.next(); });
yield;
}
is(callbackCount, readerCount + writerCount, "All requests accounted for");
finishTest();
yield;
}
</script>
<script type="text/javascript;version=1.7" src="helpers.js"></script>
</head>
<body onload="runTest();"></body>
</html>