Skip to content

Commit

Permalink
Update other servers
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 7ed0063 commit 167723a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 33 deletions.
13 changes: 7 additions & 6 deletions packages/connect-express/conformance/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
ServerCompatResponse,
ServerStreamRequest,
UnaryRequest,
writeSizeDelimitedBuffer,
} from "@connectrpc/connect-conformance";
import express from "express";
import { expressConnectMiddleware } from "../src/index.js";
Expand Down Expand Up @@ -104,8 +105,12 @@ function main() {
}

process.on("SIGTERM", () => {
server.close();
// Gracefully shutting down a http2 server is complicated.
// We trust the conformance test runner to only send the SIGNAL if it's done,
// so we simply shut down hard.
process.exit();
});

server.listen(undefined, "127.0.0.1", () => {
const addrInfo = server.address() as net.AddressInfo;
const res = new ServerCompatResponse({
Expand All @@ -116,10 +121,6 @@ function main() {
host: addrInfo.address,
port: addrInfo.port,
});
const data = res.toBinary();
const size = Buffer.alloc(4);
size.writeUInt32BE(data.byteLength);
process.stdout.write(size);
process.stdout.write(data);
process.stdout.write(writeSizeDelimitedBuffer(res.toBinary()));
});
}
13 changes: 7 additions & 6 deletions packages/connect-fastify/conformance/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
ServerCompatResponse,
ServerStreamRequest,
UnaryRequest,
writeSizeDelimitedBuffer,
} from "@connectrpc/connect-conformance";
import { fastify } from "fastify";
import type {
Expand Down Expand Up @@ -136,8 +137,12 @@ function main() {
}

process.on("SIGTERM", () => {
void server.close();
// Gracefully shutting down a http2 server is complicated.
// We trust the conformance test runner to only send the SIGNAL if it's done,
// so we simply shut down hard.
process.exit();
});

server.listen({ host: "127.0.0.1", port: 0 }, () => {
const addrInfo = server.addresses()[0];
const res = new ServerCompatResponse({
Expand All @@ -148,10 +153,6 @@ function main() {
host: addrInfo.address,
port: addrInfo.port,
});
const data = res.toBinary();
const size = Buffer.alloc(4);
size.writeUInt32BE(data.byteLength);
process.stdout.write(size);
process.stdout.write(data);
process.stdout.write(writeSizeDelimitedBuffer(res.toBinary()));
});
}
24 changes: 3 additions & 21 deletions packages/connect-node/conformance/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,13 @@ import {

main();

process.on("exit", () => {
console.error(process.pid, "connect-node/conformance/server.ts exit");
});


/**
* This program implements a server under test for the connect conformance test
* runner. It reads ServerCompatRequest messages from stdin, starts the server
* with the requested configuration, and writes a ServerCompatResponse with the
* server's port and other details to stdout.
*/
function main() {
console.error(process.pid, "connect-node/conformance/server.ts main()");
const req = ServerCompatRequest.fromBinary(
readFileSync(process.stdin.fd).subarray(4),
);
Expand Down Expand Up @@ -95,7 +89,6 @@ function main() {
};
}
}
const h2Sessions = new Set<http2.ServerHttp2Session>();
switch (req.httpVersion) {
case HTTPVersion.HTTP_VERSION_1:
server = req.useTls
Expand All @@ -106,7 +99,6 @@ 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 @@ -115,20 +107,10 @@ function main() {
}

process.on("SIGTERM", () => {
// Gracefully shutting down a http2 server is complicated.
// We trust the conformance test runner to only send the SIGNAL if it's done,
// so we simply shut down hard.
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", () => {
Expand Down

0 comments on commit 167723a

Please sign in to comment.