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