Adding a self test to check that web workers are supported

This commit is contained in:
Eric van der Vlist 2023-03-11 18:35:14 +01:00
parent ba14181bdd
commit ef909b475b
3 changed files with 56 additions and 35 deletions

View File

@ -1,55 +1,66 @@
import { import {
Icon,
ListItem, ListItem,
ListItemButton, ListItemButton,
ListItemIcon, ListItemIcon,
ListItemText, ListItemText,
SvgIcon,
} from '@suid/material'; } from '@suid/material';
import { Component, createSignal, Show } from 'solid-js'; import { Component, createEffect, createSignal, For, Show } from 'solid-js';
import SystemSecurityUpdateWarningIcon from '@suid/icons-material/SystemSecurityUpdateWarning'; import SystemSecurityUpdateWarningIcon from '@suid/icons-material/SystemSecurityUpdateWarning';
import Dialog from '../dialog'; import Dialog from '../dialog';
import dispatch from '../../workers/dispatcher-main'; import dispatch from '../../workers/dispatcher-main';
const [error, setError] = createSignal<any[]>([]);
export const reportError = (err: any) => {
setError([...error(), err]);
};
interface Props {} interface Props {}
const SystemInfo: Component<Props> = (props) => { const SystemInfo: Component<Props> = (props) => {
const [open, setOpen] = createSignal(false); const [open, setOpen] = createSignal(false);
const [settings, setSettings] = createSignal<any>(); const [settings, setSettings] = createSignal<any>();
const [account, setAccount] = createSignal<any>(); const [account, setAccount] = createSignal<any>();
const [error, setError] = createSignal<any>();
const openDialog = () => { createEffect(() => {
setOpen(true); if (error().length > 0 && !open()) {
dispatch( openDialog();
{
action: 'getSettings',
},
(error, result) => {
console.log({ caller: 'SystemInfo', error, result });
if (!!error) {
setError(error);
} }
if (!!result) { });
setSettings(result);
dispatch( const selfTest = async () => {
{ try {
const pong = await dispatch({
action: 'ping',
params: { what: 'ping' },
});
if (pong !== 'ping pong') {
throw new Error(
`web worker test error, received "${pong}" instead of expected "ping pong"`
);
}
} catch (err) {
reportError(err);
}
};
selfTest();
const openDialog = async () => {
setOpen(true);
try {
const sets: any = await dispatch({
action: 'getSettings',
});
setSettings(sets);
const acc: any = await dispatch({
action: 'getAccount', action: 'getAccount',
params: { id: settings().currentAccountId }, params: { id: settings().currentAccountId },
}, });
(error, result) => { setAccount(acc);
console.log({ caller: 'SystemInfo', error, result }); } catch (err) {
if (!!error) { reportError(err);
setError(error);
} }
if (!!result) {
setAccount(result);
}
}
);
}
}
);
}; };
return ( return (
@ -77,6 +88,14 @@ const SystemInfo: Component<Props> = (props) => {
<p>Remote DB user: {account()?.remoteDbUser}</p> <p>Remote DB user: {account()?.remoteDbUser}</p>
<p>Remote DB server: {account()?.remoteDbServer}</p> <p>Remote DB server: {account()?.remoteDbServer}</p>
</div> </div>
<Show when={error().length > 0}>
<div>
<p>Errors:</p>
<ul>
<For each={error()}>{(item) => <li>{item.message}</li>}</For>
</ul>
</div>
</Show>
</Dialog> </Dialog>
</Show> </Show>
</> </>

View File

@ -0,0 +1 @@
export { default, reportError } from './SystemInfo';

View File

@ -27,7 +27,6 @@ import { deleteTrk, getTrk, putNewTrk } from '../db/trk';
import { putTrkpt } from '../db/trkpt'; import { putTrkpt } from '../db/trkpt';
import { getTrkseg, appendTrkpt } from '../db/trkseg'; import { getTrkseg, appendTrkpt } from '../db/trkseg';
import { getWpt, putWpt, deleteWpt } from '../db/wpt'; import { getWpt, putWpt, deleteWpt } from '../db/wpt';
import { until } from '../lib/async-wait';
//const self = globalThis as unknown as WorkerGlobalScope; //const self = globalThis as unknown as WorkerGlobalScope;
@ -75,6 +74,8 @@ onmessage = async function (e) {
putAccount, putAccount,
getCurrentAccount, getCurrentAccount,
putCurrentAccount, putCurrentAccount,
ping: (params: any) => `${params.what} pong`,
}; };
// console.log({ caller: 'dispatcher-worker / onmessage', e }); // console.log({ caller: 'dispatcher-worker / onmessage', e });