diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-10-12 16:03:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-12 14:03:19 +0000 |
commit | cee221109a61406004817b09361bf3674ab06cde (patch) | |
tree | 026773e765c2433d6256a9b4b8b423e0f26cbad1 /cli | |
parent | 2fb9ddd2e6d6a89ee3c362038581b37e9d388c92 (diff) |
fix(node/http2): fixes to support grpc (#20712)
This commit improves "node:http2" module implementation, by enabling
to use "options.createConnection" callback when starting an HTTP2
session.
This change enables to pass basic client-side test with "grpc-js/grpc"
package.
Smaller fixes like "Http2Session.unref()" and "Http2Session.setTimeout()"
were handled as well.
Fixes #16647
Diffstat (limited to 'cli')
-rw-r--r-- | cli/tests/unit_node/http2_test.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/cli/tests/unit_node/http2_test.ts b/cli/tests/unit_node/http2_test.ts index 8e7b261ae..d0e0de43f 100644 --- a/cli/tests/unit_node/http2_test.ts +++ b/cli/tests/unit_node/http2_test.ts @@ -63,6 +63,52 @@ for (const url of ["http://127.0.0.1:4246", "https://127.0.0.1:4247"]) { }); } +Deno.test(`[node/http2 client createConnection]`, { + ignore: Deno.build.os === "windows", +}, async () => { + const url = "http://127.0.0.1:4246"; + const createConnPromise = deferred(); + // Create a server to respond to the HTTP2 requests + const client = http2.connect(url, { + createConnection() { + const socket = net.connect({ host: "127.0.0.1", port: 4246 }); + + socket.on("connect", () => { + createConnPromise.resolve(); + }); + + return socket; + }, + }); + client.on("error", (err) => console.error(err)); + + const req = client.request({ ":method": "POST", ":path": "/" }); + + let receivedData = ""; + + req.write("hello"); + req.setEncoding("utf8"); + + req.on("data", (chunk) => { + receivedData += chunk; + }); + req.end(); + + const endPromise = deferred(); + setTimeout(() => { + try { + client.close(); + } catch (_) { + // pass + } + endPromise.resolve(); + }, 2000); + + await createConnPromise; + await endPromise; + assertEquals(receivedData, "hello world\n"); +}); + // TODO(bartlomieju): reenable sanitizers Deno.test("[node/http2 server]", { sanitizeOps: false }, async () => { const server = http2.createServer(); |