Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/python/python-wasm/src/test/posix/spawn.test.ts
1067 views
1
import { syncPython } from "../../node";
2
3
test("test that a few spawn related posix calls throw an error (rather than getting stubbed and silently failing)", async () => {
4
const { kernel } = await syncPython();
5
const env: any = {};
6
kernel.posixContext?.injectFunctions({ env, wasi_snapshot_preview1: {} });
7
expect(env["posix_spawn"]()).toBe(-1);
8
expect(env["posix_spawnp"]()).toBe(-1);
9
});
10
11
test("posix_spawn /bin/sleep and wait for it to finish and confirm the time", async () => {
12
const { exec } = await syncPython();
13
const t0 = new Date().valueOf();
14
exec(
15
"import os; os.waitpid(os.posix_spawn('/bin/sleep', ['/bin/sleep', '0.5'], {}), 0)"
16
);
17
const tm = new Date().valueOf() - t0;
18
expect(tm > 400 && tm < 2000).toBe(true);
19
});
20
21
test("posix_spawnp sleep and wait for it to finish and confirm the time", async () => {
22
const { exec } = await syncPython();
23
const t0 = new Date().valueOf();
24
await exec(
25
"import os; os.waitpid(os.posix_spawnp('sleep', ['sleep', '0.5'], {}), 0)"
26
);
27
const tm = new Date().valueOf() - t0;
28
expect(tm > 400 && tm < 2000).toBe(true);
29
});
30
31