Skip to content

Commit 6bed395

Browse files
authored
Add a way to clear all IndexedDB databases in browser tests (emscripten-core#23408)
Without this, `browser.test_preload_caching` works once, but running it again finds the cached data and makes it error. Also clean up the test a little while there. Unblocks the test for emscripten-core#23059
1 parent 8e660ed commit 6bed395

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

test/test_browser.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,13 +560,33 @@ def test_output_file_escaping(self):
560560
self.compile_btest(src, ['--pre-js', data_js_file, '-o', abs_page_file, '-sFORCE_FILESYSTEM'], reporting=Reporting.JS_ONLY)
561561
self.run_browser(page_file, '/report_result?exit:0')
562562

563+
# Clear all IndexedDB databases. This gives us a fresh state for tests that
564+
# chech caching.
565+
def clear_indexed_db(self):
566+
shutil.copy(test_file('browser_reporting.js'), '.')
567+
create_file('clear_indexed_db.html', '''
568+
<script src="browser_reporting.js"></script>
569+
<script>
570+
// Clear the cache, so that the next test starts from a clean slate.
571+
indexedDB.databases().then(dbs => {
572+
Promise.all(dbs.map(db => {
573+
return indexedDB.deleteDatabase(db.name);
574+
})).then(() => {
575+
reportResultToServer("clear");
576+
});
577+
});
578+
</script>
579+
''')
580+
self.run_browser('clear_indexed_db.html', '/report_result?clear')
581+
563582
@parameterized({
564583
'0': (0,),
565584
'1mb': (1 * 1024 * 1024,),
566585
'100mb': (100 * 1024 * 1024,),
567586
'150mb': (150 * 1024 * 1024,),
568587
})
569588
def test_preload_caching(self, extra_size):
589+
self.clear_indexed_db()
570590
self.set_setting('EXIT_RUNTIME')
571591
create_file('main.c', r'''
572592
#include <assert.h>
@@ -596,8 +616,9 @@ def test_preload_caching(self, extra_size):
596616
var packages = Object.keys(Module['preloadResults']);
597617
packages.forEach(function(package) {
598618
var fromCache = Module['preloadResults'][package]['fromCache'];
599-
if (fromCache)
600-
++ cached;
619+
if (fromCache) {
620+
cached++;
621+
}
601622
});
602623
return cached;
603624
}

0 commit comments

Comments
 (0)