Skip to content

Commit

Permalink
Test node server
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Stamm <ts@timostamm.de>
  • Loading branch information
timostamm committed Aug 30, 2024
1 parent 5c6d118 commit cc4cd33
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/conformance-node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
41 changes: 20 additions & 21 deletions packages/connect-node/conformance/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Check failure on line 44 in packages/connect-node/conformance/server.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
});


Expand All @@ -57,14 +52,9 @@ process.on("exit", () => {
* server's port and other details to stdout.
*/
function main() {

Check failure on line 54 in packages/connect-node/conformance/server.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
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({
Expand Down Expand Up @@ -105,6 +95,7 @@ function main() {
};
}
}
const h2Sessions = new Set<http2.ServerHttp2Session>();
switch (req.httpVersion) {
case HTTPVersion.HTTP_VERSION_1:
server = req.useTls
Expand All @@ -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");
Expand All @@ -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:
Expand All @@ -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()));
});
}
4 changes: 2 additions & 2 deletions packages/connect-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand Down

0 comments on commit cc4cd33

Please sign in to comment.