diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/IndexedDB/writer-starvation.htm | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/IndexedDB/writer-starvation.htm')
-rw-r--r-- | testing/web-platform/tests/IndexedDB/writer-starvation.htm | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/testing/web-platform/tests/IndexedDB/writer-starvation.htm b/testing/web-platform/tests/IndexedDB/writer-starvation.htm new file mode 100644 index 0000000000..df9c5dc757 --- /dev/null +++ b/testing/web-platform/tests/IndexedDB/writer-starvation.htm @@ -0,0 +1,105 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<title>Writer starvation</title> +<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal"> +<meta name=timeout content=long> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=resources/support.js></script> + +<script> + var db, read_request_count = 0, read_success_count = 0; + var write_request_count = 0, write_success_count = 0; + var RQ_COUNT = 25; + + var open_rq = createdb(async_test(undefined)); + open_rq.onupgradeneeded = function(e) { + db = e.target.result; + db.createObjectStore("s") + .add("1", 1); + } + + open_rq.onsuccess = function(e) { + var i = 0, continue_reading = true; + + /* Pre-fill some read requests */ + for (i = 0; i < RQ_COUNT; i++) + { + read_request_count++; + + db.transaction("s", "readonly", {durability: 'relaxed'}) + .objectStore("s") + .get(1) + .onsuccess = this.step_func(function(e) { + read_success_count++; + assert_equals(e.target.transaction.mode, "readonly"); + }); + } + + this.step(loop); + + function loop() { + read_request_count++; + + db.transaction("s", "readonly", {durability: 'relaxed'}) + .objectStore("s") + .get(1) + .onsuccess = this.step_func(function(e) + { + read_success_count++; + assert_equals(e.target.transaction.mode, "readonly"); + + if (read_success_count >= RQ_COUNT && write_request_count == 0) + { + write_request_count++; + + db.transaction("s", "readwrite", {durability: 'relaxed'}) + .objectStore("s") + .add("written", read_request_count) + .onsuccess = this.step_func(function(e) + { + write_success_count++; + assert_equals(e.target.transaction.mode, "readwrite"); + assert_equals(e.target.result, read_success_count, + "write cb came before later read cb's") + }); + + /* Reads done after the write */ + for (i = 0; i < 5; i++) + { + read_request_count++; + + db.transaction("s", "readonly", {durability: 'relaxed'}) + .objectStore("s") + .get(1) + .onsuccess = this.step_func(function(e) + { + read_success_count++; + }); + } + } + }); + + if (read_success_count < RQ_COUNT + 5) + step_timeout(this.step_func(loop), write_request_count ? 1000 : 100); + else + // This is merely a "nice" hack to run finish after the last request is done + db.transaction("s", "readonly", {durability: 'relaxed'}) + .objectStore("s") + .count() + .onsuccess = this.step_func(function() + { + step_timeout(this.step_func(finish), 100); + }); + } + } + + +function finish() { + assert_equals(read_request_count, read_success_count, "read counts"); + assert_equals(write_request_count, write_success_count, "write counts"); + this.done(); +} +</script> + +<div id=log></div> |