Live video on the AT Protocol

desktop: fix tests ending early, run tests in parallel

+65 -55
+9 -5
js/desktop/src/index.ts
··· 51 51 SP_ALLOWED_STREAMS: account.address.toLowerCase(), 52 52 }; 53 53 if (args["self-test"]) { 54 + app.on("window-all-closed", () => { 55 + // need to override this to prevent the app from quitting 56 + }); 54 57 const success = await runTests( 55 58 args["tests-to-run"].split(","), 56 59 args["self-test-duration"], 57 60 privateKey, 58 61 ); 62 + console.log("tests finished"); 59 63 if (!success) { 60 64 app.exit(1); 61 65 } else { ··· 82 86 }); 83 87 84 88 const start = async (env: { [k: string]: string }): Promise<void> => { 89 + app.on("window-all-closed", () => { 90 + if (process.platform !== "darwin") { 91 + app.quit(); 92 + } 93 + }); 85 94 const { skipNode, nodeFrontend, noUpdate } = getEnv(); 86 95 if (!noUpdate) { 87 96 initUpdater(); ··· 110 119 // Quit when all windows are closed, except on macOS. There, it's common 111 120 // for applications and their menu bar to stay active until the user quits 112 121 // explicitly with Cmd + Q. 113 - // app.on("window-all-closed", () => { 114 - // if (process.platform !== "darwin") { 115 - // app.quit(); 116 - // } 117 - // }); 118 122 119 123 app.on("activate", () => { 120 124 // On OS X it's common to re-create a window in the app when the
+2
js/desktop/src/node.ts
··· 56 56 57 57 if (opts.autoQuit) { 58 58 app.on("before-quit", () => { 59 + console.log("before-quit"); 59 60 proc.kill("SIGTERM"); 60 61 }); 61 62 } 62 63 proc.on("exit", () => { 63 64 console.log("node exited"); 64 65 if (opts.autoQuit) { 66 + console.log("exiting app"); 65 67 app.quit(); 66 68 } 67 69 });
+54 -50
js/desktop/src/tests/test-runner.ts
··· 9 9 import { playbackTest } from "./playback-test"; 10 10 import { resumeLoopTest } from "./resume-loop-test"; 11 11 import { serverRestartTest } from "./server-restart-test"; 12 - import { syncTest } from "./sync-test"; 13 12 import { E2ETest, TestEnv } from "./test-env"; 14 13 import { randomPort } from "./util"; 15 14 16 15 const allTests: Record<string, E2ETest> = { 17 16 playback: playbackTest, 18 - sync: syncTest, 17 + // sync: syncTest, 19 18 resume: resumeLoopTest, 20 19 serverRestart: serverRestartTest, 21 20 }; ··· 35 34 testsToRun.push(test); 36 35 } 37 36 try { 38 - const results = []; 37 + const results: string[] = []; 38 + const proms: Promise<void>[] = []; 39 39 for (const testName of testsToRun) { 40 40 const test = allTests[testName]; 41 41 console.log(`============ running test ${testName} ============`); 42 42 let testProc: ChildProcess | undefined; 43 - try { 44 - const { skipNode } = getEnv(); 45 - const hexKey = privateKey.slice(2); // Remove 0x prefix 46 - const exportedKey = new Uint8Array( 47 - hexKey.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)), 48 - ); 49 - const multibaseKey = bytesToMultibase(exportedKey, "base58btc"); 50 - const account = privateKeyToAccount(privateKey); 51 - const tmpDir = await fs.mkdtemp( 52 - path.join(os.tmpdir(), "streamplace-test-"), 53 - ); 43 + const prom = (async (test) => { 44 + try { 45 + const { skipNode } = getEnv(); 46 + const hexKey = privateKey.slice(2); // Remove 0x prefix 47 + const exportedKey = new Uint8Array( 48 + hexKey.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)), 49 + ); 50 + const multibaseKey = bytesToMultibase(exportedKey, "base58btc"); 51 + const account = privateKeyToAccount(privateKey); 52 + const tmpDir = await fs.mkdtemp( 53 + path.join(os.tmpdir(), "streamplace-test-"), 54 + ); 54 55 55 - let testEnv: TestEnv = { 56 - addr: "http://127.0.0.1:38080", 57 - internalAddr: "http://127.0.0.1:39090", 58 - privateKey: privateKey, 59 - publicAddress: account.address.toLowerCase(), 60 - testDuration: parseInt(duration), 61 - multibaseKey, 62 - env: {}, 63 - }; 64 - if (!skipNode) { 65 - testEnv.env = { 66 - SP_HTTP_ADDR: `127.0.0.1:${randomPort()}`, 67 - SP_HTTP_INTERNAL_ADDR: `127.0.0.1:${randomPort()}`, 68 - SP_DATA_DIR: tmpDir, 56 + let testEnv: TestEnv = { 57 + addr: "http://127.0.0.1:38080", 58 + internalAddr: "http://127.0.0.1:39090", 59 + privateKey: privateKey, 60 + publicAddress: account.address.toLowerCase(), 61 + testDuration: parseInt(duration), 62 + multibaseKey, 63 + env: {}, 69 64 }; 70 - } 71 - if (test.setup) { 72 - testEnv = await test.setup(testEnv); 73 - } 74 - if (!skipNode) { 75 - const { addr, internalAddr, proc } = await makeNode({ 76 - env: testEnv.env, 77 - autoQuit: false, 78 - }); 79 - testEnv.addr = addr; 80 - testEnv.internalAddr = internalAddr; 81 - testProc = proc; 82 - } 83 - const result = await test.test(testEnv); 84 - results.push(result); 85 - } catch (e) { 86 - console.error("error running test", e.message); 87 - results.push(e.message); 88 - } finally { 89 - if (testProc) { 90 - testProc.kill("SIGTERM"); 65 + if (!skipNode) { 66 + testEnv.env = { 67 + SP_HTTP_ADDR: `127.0.0.1:${randomPort()}`, 68 + SP_HTTP_INTERNAL_ADDR: `127.0.0.1:${randomPort()}`, 69 + SP_DATA_DIR: tmpDir, 70 + }; 71 + } 72 + if (test.setup) { 73 + testEnv = await test.setup(testEnv); 74 + } 75 + if (!skipNode) { 76 + const { addr, internalAddr, proc } = await makeNode({ 77 + env: testEnv.env, 78 + autoQuit: false, 79 + }); 80 + testEnv.addr = addr; 81 + testEnv.internalAddr = internalAddr; 82 + testProc = proc; 83 + } 84 + const result = await test.test(testEnv); 85 + results.push(result); 86 + } catch (e) { 87 + console.error("error running test", e.message); 88 + results.push(e.message); 89 + } finally { 90 + if (testProc) { 91 + testProc.kill("SIGTERM"); 92 + } 91 93 } 92 - } 94 + })(test); 95 + proms.push(prom); 93 96 } 97 + await Promise.all(proms); 94 98 const failures = results.filter((r) => r !== null); 95 99 if (failures.length > 0) { 96 100 console.error("tests failed", failures.join(", "));