Skip to content

Commit

Permalink
IDBFactory databases flaky wpt fix.
Browse files Browse the repository at this point in the history
Converting databases() wpt tests to promise_tests to fix flakiness

Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=899085
Change-Id: I91848796d7508408bb3e5b9fb05f725564fa9971
Reviewed-on: https://chromium-review.googlesource.com/c/1299959
Reviewed-by: Victor Costan <pwnall@chromium.org>
Reviewed-by: Chase Phillips <cmp@chromium.org>
Commit-Queue: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603701}
  • Loading branch information
andreas-butler authored and chromium-wpt-export-bot committed Oct 30, 2018
1 parent 7b94252 commit c169e95
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 94 deletions.
108 changes: 60 additions & 48 deletions IndexedDB/get-databases.any.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,62 @@
// META: script=support.js

async_test( async function(t) {
let made_database_check = t.step_func(async function() {
let idb_databases_promise = await indexedDB.databases();
assert_true(
idb_databases_promise.some(
e => e.name == "TestDatabase" && e.version == 1),
"Call to databases() did not find database.");
t.done();
});
delete_then_open(t, "TestDatabase", ()=>{}, made_database_check);
}, "Report one database test.");

async_test( function(t) {
let done_making_databases_callback = t.step_func(async function() {
let idb_databases_promise = await indexedDB.databases();
assert_true(
idb_databases_promise.some(
e => e.name == "TestDatabase1" && e.version == 1),
"Call to databases() did not find database.");
assert_true(
idb_databases_promise.some(
e => e.name == "TestDatabase2" && e.version == 1),
"Call to databases() did not find database.");
assert_true(
idb_databases_promise.some(
e => e.name == "TestDatabase3" && e.version == 1),
"Call to databases() did not find database.");
t.done();
});
let make_databases_barrier = create_barrier(done_making_databases_callback);
delete_then_open(t, "TestDatabase1", ()=>{}, make_databases_barrier(t));
delete_then_open(t, "TestDatabase2", ()=>{}, make_databases_barrier(t));
delete_then_open(t, "TestDatabase3", ()=>{}, make_databases_barrier(t));
}, "Report multiple databases test.");

async_test( function(t) {
let delete_request = indexedDB.deleteDatabase("NonExistentDatabase");
delete_request.onsuccess = t.step_func(async function() {
let idb_databases_promise = await indexedDB.databases();
assert_false(
idb_databases_promise.some(
e => e.name == "NonExistentDatabase"),
"Call to databases() found excluded database.");
t.done();
});
}, "Don't report nonexistant databases test.");
// META: script=support-promises.js

promise_test(async testCase => {
// Delete any databases that may not have been cleaned up after
// previous test runs.
await deleteAllDatabases(testCase);

const db_name = "TestDatabase";
const db = await createNamedDatabase(testCase, db_name, ()=>{});
const databases_promise = await indexedDB.databases();
const expected_result = [
{"name": db_name, "version": 1},
];
assert_object_equals(
databases_promise,
expected_result,
"Call to databases() did not retrieve the single expected result.");
}, "Enumerate one database.");

promise_test(async testCase => {
// Delete any databases that may not have been cleaned up after previous test
// runs.
await deleteAllDatabases(testCase);

const db_name1 = "TestDatabase1";
const db_name2 = "TestDatabase2";
const db_name3 = "TestDatabase3";
const db1 = await createNamedDatabase(testCase, db_name1, ()=>{});
const db2 = await createNamedDatabase(testCase, db_name2, ()=>{});
const db3 = await createNamedDatabase(testCase, db_name3, ()=>{});
const databases_promise = await indexedDB.databases();
const expected_result = [
{"name": db_name1, "version": 1},
{"name": db_name2, "version": 1},
{"name": db_name3, "version": 1},
];
assert_object_equals(
databases_promise,
expected_result,
"Call to databases() did not retrieve the multiple expected results");
}, "Enumerate multiple databases.");

promise_test(async testCase => {
// Add some databases and close their connections.
const db1 = await createNamedDatabase(testCase, "DB1", ()=>{});
const db2 = await createNamedDatabase(testCase, "DB2", ()=>{});
db1.onversionchange = () => { db1.close() };
db2.onversionchange = () => { db2.close() };

// Delete any databases that may not have been cleaned up after previous test
// runs as well as the two databases made above.
await deleteAllDatabases(testCase);

// Make sure the databases are no longer returned.
const databases_promise = await indexedDB.databases();
assert_object_equals(
databases_promise,
[],
"Call to databases() found database it should not have.")
}, "Make sure an empty list is returned for the case of no databases.");

done();
9 changes: 9 additions & 0 deletions IndexedDB/support-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,12 @@ function largeValue(size, seed) {

return buffer;
}

async function deleteAllDatabases(testCase) {
const dbs_to_delete = await indexedDB.databases();
for( const db_info of dbs_to_delete) {
let request = indexedDB.deleteDatabase(db_info.name);
let eventWatcher = requestWatcher(testCase, request);
await eventWatcher.wait_for('success');
}
}
46 changes: 0 additions & 46 deletions IndexedDB/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,49 +192,3 @@ function keep_alive(tx, store_name) {
pin = false;
};
}

/**
* Ensures that indexeddb database specified by db_name is deleted, and then
* opens a connection to that database.
*
* @param t: the testing script state
* @param db_name: name of database to delete then create
* @param upgrade_func: function to be called if db_name needs upgrading
* @param body_func: function to be called upon successful deletion
* and creation of db_name
*/
function delete_then_open(t, db_name, upgrade_func, body_func) {
var delete_request = indexedDB.deleteDatabase(db_name);
delete_request.onerror = t.unreached_func('deleteDatabase should not fail');
delete_request.onsuccess = t.step_func(function(e) {
var open_request = indexedDB.open(db_name);
open_request.onupgradeneeded = t.step_func(function() {
upgrade_func(t, open_request.result, open_request);
});
open_request.onsuccess = t.step_func(function() {
body_func(t, open_request.result);
});
});
}

/**
* Creates a barrier that one calls
*
* @param callback: function to be called after barrier is passed
*/
function create_barrier(callback) {
var count = 0;
var called = false;
return function(t) {
assert_false(called, "Barrier already used.");
++count;
return t.step_func(function() {
--count;
if (count === 0) {
assert_false(called, "Barrier already used.");
called = true;
callback();
}
});
}
}

0 comments on commit c169e95

Please sign in to comment.