1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Add worker-style variant of the tests added in [ae24ac0f7dd9], but building this with wasmfs causes them to throw inexplicable exceptions from the Emscripten glue (without wasmfs it builds and runs fine, but storage is not persistent).

FossilOrigin-Name: 6401595e59179c5c0f6e51c5362cf4391787e7a55b9c6ca655746e30d3251f2b
This commit is contained in:
stephan
2022-08-13 17:13:16 +00:00
parent a7234901b2
commit 0761780bc4
5 changed files with 167 additions and 6 deletions

View File

@ -0,0 +1,86 @@
/*
2022-05-22
The author disclaims copyright to this source code. In place of a
legal notice, here is a blessing:
* May you do good and not evil.
* May you find forgiveness for yourself and forgive others.
* May you share freely, never taking more than you give.
***********************************************************************
An experiment for wasmfs/opfs. This file MUST be in the same dir as
the sqlite3.js emscripten module or that module won't be able to
resolve the relative URIs (importScript()'s relative URI handling
is, quite frankly, broken).
*/
'use strict';
(function(){
const toss = function(...args){throw new Error(args.join(' '))};
importScripts('sqlite3.js');
/**
Posts a message in the form {type,data} unless passed more than 2
args, in which case it posts {type, data:[arg1...argN]}.
*/
const wMsg = function(type,data){
postMessage({
type,
data: arguments.length<3
? data
: Array.prototype.slice.call(arguments,1)
});
};
const stdout = console.log.bind(console);
const stderr = function(...args){wMsg('stderr', args);};
const test1 = function(db){
db.execMulti("create table if not exists t(a);")
.callInTransaction(function(db){
db.prepare("insert into t(a) values(?)")
.bind(new Date().getTime())
.stepFinalize();
stdout("Number of values in table t:",
db.selectValue("select count(*) from t"));
});
};
const runTests = function(Module){
//stdout("Module",Module);
self._MODULE = Module /* this is only to facilitate testing from the console */;
const sqlite3 = Module.sqlite3,
capi = sqlite3.capi,
oo = sqlite3.oo1,
wasm = capi.wasm;
stdout("Loaded sqlite3:",capi.sqlite3_libversion(), capi.sqlite3_sourceid());
const persistentDir = capi.sqlite3_web_persistent_dir();
if(persistentDir){
stderr("Persistent storage dir:",persistentDir);
}else{
stderr("No persistent storage available.");
}
const startTime = performance.now();
let db;
try {
db = new oo.DB(persistentDir+'/foo.db');
stdout("DB filename:",db.filename,db.fileName());
const banner1 = '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>',
banner2 = '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<';
[
test1
].forEach((f)=>{
const n = performance.now();
stdout(banner1,"Running",f.name+"()...");
f(db, sqlite3, Module);
stdout(banner2,f.name+"() took ",(performance.now() - n),"ms");
});
}finally{
if(db) db.close();
}
stdout("Total test time:",(performance.now() - startTime),"ms");
};
sqlite3InitModule(self.sqlite3TestModule).then(runTests);
})();

View File

@ -0,0 +1,39 @@
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
<link rel="stylesheet" href="common/emscripten.css"/>
<link rel="stylesheet" href="common/testing.css"/>
<title>sqlite3 WASMFS/OPFS Worker-thread Scratchpad</title>
</head>
<body>
<header id='titlebar'><span>sqlite3 WASMFS/OPFS Worker-thread Scratchpad</span></header>
<!-- emscripten bits -->
<!--figure id="module-spinner">
<div class="spinner"></div>
<div class='center'><strong>Initializing app...</strong></div>
<div class='center'>
On a slow internet connection this may take a moment. If this
message displays for "a long time", intialization may have
failed and the JavaScript console may contain clues as to why.
</div>
</figure>
<div class="emscripten" id="module-status">Downloading...</div>
<div class="emscripten">
<progress value="0" max="100" id="module-progress" hidden='1'></progress>
</div--><!-- /emscripten bits -->
<p><strong>This test is known, as of 2022-08-13, to not work.</strong></p>
<p>Scratchpad/test app for the WASMF/OPFS integration in a
WORKER thread. This page requires that the sqlite3 API have
been built with WASMFS support. If OPFS support is available then
it "should" persist a database across reloads (watch the dev console
output), otherwise it will not.
</p>
<p>All stuff on this page happens in the dev console.</p>
<hr>
<div id='test-output'></div>
<script src="scratchpad-opfs-worker.js"></script>
</body>
</html>

View File

@ -0,0 +1,33 @@
/*
2022-05-22
The author disclaims copyright to this source code. In place of a
legal notice, here is a blessing:
* May you do good and not evil.
* May you find forgiveness for yourself and forgive others.
* May you share freely, never taking more than you give.
***********************************************************************
A basic test script for sqlite3-api.js. This file must be run in
main JS thread and sqlite3.js must have been loaded before it.
*/
'use strict';
(function(){
const toss = function(...args){throw new Error(args.join(' '))};
const log = console.log.bind(console),
warn = console.warn.bind(console),
error = console.error.bind(console);
const W = new Worker("api/scratchpad-opfs-worker.js");
self.onmessage = function(ev){
ev = ev.data;
const d = ev.data;
switch(ev.type){
case 'stdout': log(d); break;
case 'stderr': error(d); break;
default: warn("Unhandled message type:",ev); break;
}
};
})();