From cc4cd330bf346dd541dde12b7e4f063ede0eb0ae Mon Sep 17 00:00:00 2001 From: Timo Stamm Date: Fri, 30 Aug 2024 13:11:02 +0200 Subject: [PATCH] Test node server Signed-off-by: Timo Stamm --- .github/workflows/conformance-node.yaml | 3 +- packages/connect-node/conformance/server.ts | 41 ++++++++++----------- packages/connect-node/package.json | 4 +- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/.github/workflows/conformance-node.yaml b/.github/workflows/conformance-node.yaml index d8b639d15..7c28ef3aa 100644 --- a/.github/workflows/conformance-node.yaml +++ b/.github/workflows/conformance-node.yaml @@ -56,4 +56,5 @@ jobs: - name: NPM Install run: npm ci - run: npx turbo run build --filter '@connectrpc/connect-node' --output-logs new-only --log-order stream - - run: npm run conformance:server -w @connectrpc/connect-node + # - run: npm run conformance:server -w @connectrpc/connect-node + - run: npx turbo run conformance:server --filter '@connectrpc/connect-node' --output-logs new-only --log-order stream diff --git a/packages/connect-node/conformance/server.ts b/packages/connect-node/conformance/server.ts index 7ad82bdaf..35b0cf220 100755 --- a/packages/connect-node/conformance/server.ts +++ b/packages/connect-node/conformance/server.ts @@ -40,13 +40,8 @@ import { main(); - -process.on("beforeExit", () => { - console.error("connect-node/conformance/server.ts beforeExit", process.pid); -}); - process.on("exit", () => { - console.error("connect-node/conformance/server.ts exit", process.pid); + console.error(process.pid, "connect-node/conformance/server.ts exit"); }); @@ -57,14 +52,9 @@ process.on("exit", () => { * server's port and other details to stdout. */ function main() { - console.error("connect-node/conformance/server.ts main()", process.pid); - const stdinAll = readFileSync(process.stdin.fd); - const stdinMsgLen = stdinAll.readUint32BE(); - if (stdinAll.byteLength != stdinMsgLen + 4) { - throw new Error("unexpected input on stdin"); - } + console.error(process.pid, "connect-node/conformance/server.ts main()"); const req = ServerCompatRequest.fromBinary( - stdinAll.subarray(4), + readFileSync(process.stdin.fd).subarray(4), ); const adapter = connectNodeAdapter({ @@ -105,6 +95,7 @@ function main() { }; } } + const h2Sessions = new Set(); switch (req.httpVersion) { case HTTPVersion.HTTP_VERSION_1: server = req.useTls @@ -115,6 +106,7 @@ function main() { server = req.useTls ? http2.createSecureServer(serverOptions, adapter) : http2.createServer(adapter); + server.on("session", s => h2Sessions.add(s)); break; case HTTPVersion.HTTP_VERSION_3: throw new Error("HTTP/3 is not supported"); @@ -123,15 +115,23 @@ function main() { } process.on("SIGTERM", () => { - console.error("connect-node/conformance/server.ts SIGTERM", process.pid); - if ("closeAllConnections" in server) { - server.closeAllConnections(); - } - server.close(); + process.exit(); + // if ("closeAllConnections" in server) { + // console.error(process.pid, "connect-node/conformance/server.ts SIGTERM", "h1"); + // server.closeAllConnections(); + // server.close(); + // } else { + // console.error(process.pid, "connect-node/conformance/server.ts SIGTERM", "h2"); + // for (const s of h2Sessions) { + // if (!s.closed) { + // s.close(); + // } + // } + // server.close(); + // } }); server.listen(0, "127.0.0.1", () => { - console.error("connect-node/conformance/server.ts listening", process.pid); const addrInfo = server.address() as net.AddressInfo; const res = new ServerCompatResponse({ pemCert: @@ -141,7 +141,6 @@ function main() { host: addrInfo.address, port: addrInfo.port, }); - process.stdout.end(writeSizeDelimitedBuffer(res.toBinary())); - console.error("connect-node/conformance/server.ts wrote compat resp", process.pid); + process.stdout.write(writeSizeDelimitedBuffer(res.toBinary())); }); } diff --git a/packages/connect-node/package.json b/packages/connect-node/package.json index 30916d9aa..7307cb860 100644 --- a/packages/connect-node/package.json +++ b/packages/connect-node/package.json @@ -13,8 +13,8 @@ "build:cjs": "tsc --project tsconfig.build.json --module commonjs --moduleResolution node10 --verbatimModuleSyntax false --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", "build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm --declaration --declarationDir ./dist/esm", "test": "jasmine --config=jasmine.json", - "conformance:server": "tsc --noEmit && connectconformance --mode server --conf ./conformance/conformance-node.yaml -v -- npx tsx ./conformance/server.ts", - "conformance:client": "tsc --noEmit && connectconformance --mode client --conf ./conformance/conformance-node.yaml -v -- npx tsx ./conformance/client.ts", + "conformance:server": "tsc --noEmit && connectconformance --mode server --conf ./conformance/conformance-node.yaml -v -- tsx ./conformance/server.ts", + "conformance:client": "tsc --noEmit && connectconformance --mode client --conf ./conformance/conformance-node.yaml -v -- tsx ./conformance/client.ts", "format": "prettier --write --ignore-unknown '.' '!dist'", "license-header": "license-header", "lint": "eslint --max-warnings 0 .",