Skip to content

Commit

Permalink
Add test for handler in HTTP/1.1 always aborted
Browse files Browse the repository at this point in the history
Signed-off-by: Sri Krishna Paritala <skrishna@buf.build>
  • Loading branch information
srikrsna-buf committed Sep 9, 2024
1 parent 32d7ada commit 90b2bb9
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions packages/connect-node/src/node-universal-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,48 @@ describe("universalRequestFromNodeRequest()", function () {
}
});
});
describe("with HTTP/1.1", function () {
let serverRequest: UniversalServerRequest | undefined;
let serverNodeResponse:
| http.ServerResponse<http.IncomingMessage>
| undefined;
const server = useNodeServer(() =>
http.createServer(function (request, response) {
serverRequest = universalRequestFromNodeRequest(
request,
undefined,
undefined,
);
response.on("error", fail);
serverNodeResponse = response;
void readAllBytes(
serverRequest.body as AsyncIterable<Uint8Array>,
Number.MAX_SAFE_INTEGER,
).then(() => {
response.writeHead(200);
response.flushHeaders();
});
}),
);
it("signal should not be aborted on start", async function () {
await new Promise<void>((resolve) => {
const request = http.request(server.getUrl(), {
method: "POST",
// close TCP connection after we're done so that the server shuts down cleanly
agent: new http.Agent({ keepAlive: false }),
});
request.on("error", fail);
request.flushHeaders();
request.end();
request.on("response", (response) => {
expect(serverRequest).toBeDefined();
expect(serverRequest?.signal.aborted).toBeFalse();
serverNodeResponse?.end();
void readAllBytes(response, Number.MAX_SAFE_INTEGER).then(() =>
resolve(),
);
});
});
});
});
});

0 comments on commit 90b2bb9

Please sign in to comment.