Adding a self test to check that web workers are supported
This commit is contained in:
parent
ba14181bdd
commit
ef909b475b
|
@ -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) => {
|
const selfTest = async () => {
|
||||||
console.log({ caller: 'SystemInfo', error, result });
|
try {
|
||||||
if (!!error) {
|
const pong = await dispatch({
|
||||||
setError(error);
|
action: 'ping',
|
||||||
}
|
params: { what: 'ping' },
|
||||||
if (!!result) {
|
});
|
||||||
setSettings(result);
|
if (pong !== 'ping pong') {
|
||||||
dispatch(
|
throw new Error(
|
||||||
{
|
`web worker test error, received "${pong}" instead of expected "ping pong"`
|
||||||
action: 'getAccount',
|
);
|
||||||
params: { id: settings().currentAccountId },
|
|
||||||
},
|
|
||||||
(error, result) => {
|
|
||||||
console.log({ caller: 'SystemInfo', error, result });
|
|
||||||
if (!!error) {
|
|
||||||
setError(error);
|
|
||||||
}
|
|
||||||
if (!!result) {
|
|
||||||
setAccount(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
} 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',
|
||||||
|
params: { id: settings().currentAccountId },
|
||||||
|
});
|
||||||
|
setAccount(acc);
|
||||||
|
} catch (err) {
|
||||||
|
reportError(err);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
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>
|
||||||
</>
|
</>
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
export { default, reportError } from './SystemInfo';
|
|
@ -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 });
|
||||||
|
|
Loading…
Reference in New Issue