1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-06 22:35:51 -05:00

update test cases

This commit is contained in:
Yoshiya Hinosawa 2024-09-26 13:24:55 +09:00
parent 2f9cdaa67d
commit 6301b5831c
No known key found for this signature in database
GPG key ID: 9017DB4559488785
2 changed files with 247 additions and 223 deletions

View file

@ -455,10 +455,6 @@ class ClientRequest extends OutgoingMessage {
await op_node_http_wait_for_connection(connRid);
this.emit("requestReady");
const res = await op_node_http_await_response(rid);
if (this._timeout) {
this._timeout.removeEventListener("abort", this._timeoutCb);
webClearTimeout(this._timeout[timerId]);
}
const incoming = new IncomingMessageForClient(this.socket);
incoming.req = this;
this.res = incoming;

View file

@ -328,74 +328,74 @@ Deno.test("[node/http] IncomingRequest socket has remoteAddress + remotePort", a
await promise;
});
// Deno.test("[node/http] request default protocol", async () => {
// const deferred1 = Promise.withResolvers<void>();
// const deferred2 = Promise.withResolvers<void>();
// const server = http.createServer((_, res) => {
// res.end("ok");
// });
Deno.test("[node/http] request default protocol", async () => {
const deferred1 = Promise.withResolvers<void>();
const deferred2 = Promise.withResolvers<void>();
const server = http.createServer((_, res) => {
res.end("ok");
});
// // @ts-ignore IncomingMessageForClient
// // deno-lint-ignore no-explicit-any
// let clientRes: any;
// // deno-lint-ignore no-explicit-any
// let clientReq: any;
// server.listen(() => {
// clientReq = http.request(
// // deno-lint-ignore no-explicit-any
// { host: "localhost", port: (server.address() as any).port },
// (res) => {
// assert(res.socket instanceof EventEmitter);
// assertEquals(res.complete, false);
// res.on("data", () => {});
// res.on("end", () => {
// server.close();
// });
// clientRes = res;
// assertEquals(res.statusCode, 200);
// deferred2.resolve();
// },
// );
// clientReq.end();
// });
// server.on("close", () => {
// deferred1.resolve();
// });
// await deferred1.promise;
// await deferred2.promise;
// assert(clientReq.socket instanceof EventEmitter);
// assertEquals(clientRes!.complete, true);
// });
// @ts-ignore IncomingMessageForClient
// deno-lint-ignore no-explicit-any
let clientRes: any;
// deno-lint-ignore no-explicit-any
let clientReq: any;
server.listen(() => {
clientReq = http.request(
// deno-lint-ignore no-explicit-any
{ host: "localhost", port: (server.address() as any).port },
(res) => {
assert(res.socket instanceof EventEmitter);
assertEquals(res.complete, false);
res.on("data", () => {});
res.on("end", () => {
server.close();
});
clientRes = res;
assertEquals(res.statusCode, 200);
deferred2.resolve();
},
);
clientReq.end();
});
server.on("close", () => {
deferred1.resolve();
});
await deferred1.promise;
await deferred2.promise;
assert(clientReq.socket instanceof EventEmitter);
assertEquals(clientRes!.complete, true);
});
// Deno.test("[node/http] request with headers", async () => {
// const { promise, resolve } = Promise.withResolvers<void>();
// const server = http.createServer((req, res) => {
// assertEquals(req.headers["x-foo"], "bar");
// res.end("ok");
// });
// server.listen(() => {
// const req = http.request(
// {
// host: "localhost",
// // deno-lint-ignore no-explicit-any
// port: (server.address() as any).port,
// headers: { "x-foo": "bar" },
// },
// (res) => {
// res.on("data", () => {});
// res.on("end", () => {
// server.close();
// });
// assertEquals(res.statusCode, 200);
// },
// );
// req.end();
// });
// server.on("close", () => {
// resolve();
// });
// await promise;
// });
Deno.test("[node/http] request with headers", async () => {
const { promise, resolve } = Promise.withResolvers<void>();
const server = http.createServer((req, res) => {
assertEquals(req.headers["x-foo"], "bar");
res.end("ok");
});
server.listen(() => {
const req = http.request(
{
host: "localhost",
// deno-lint-ignore no-explicit-any
port: (server.address() as any).port,
headers: { "x-foo": "bar" },
},
(res) => {
res.on("data", () => {});
res.on("end", () => {
server.close();
});
assertEquals(res.statusCode, 200);
},
);
req.end();
});
server.on("close", () => {
resolve();
});
await promise;
});
Deno.test("[node/http] non-string buffer response", {
// TODO(kt3k): Enable sanitizer. A "zlib" resource is leaked in this test case.
@ -452,63 +452,68 @@ Deno.test("[node/http] http.IncomingMessage can be created without url", () => {
});
*/
// Deno.test("[node/http] send request with non-chunked body", async () => {
// let requestHeaders: Headers;
// let requestBody = "";
Deno.test(
"[node/http] send request with non-chunked body",
{ ignore: true },
async () => {
let requestHeaders: Headers;
let requestBody = "";
// const hostname = "localhost";
// const port = 4505;
const hostname = "localhost";
const port = 4505;
// const handler = async (req: Request) => {
// requestHeaders = req.headers;
// requestBody = await req.text();
// return new Response("ok");
// };
// const abortController = new AbortController();
// const servePromise = Deno.serve({
// hostname,
// port,
// signal: abortController.signal,
// onListen: undefined,
// }, handler).finished;
const handler = async (req: Request) => {
requestHeaders = req.headers;
requestBody = await req.text();
return new Response("ok");
};
const abortController = new AbortController();
const servePromise = Deno.serve({
// TODO(k3k): Enable this line for better compatibility with Node.js
// hostname,
port,
signal: abortController.signal,
onListen: undefined,
}, handler).finished;
// const opts: RequestOptions = {
// host: hostname,
// port,
// method: "POST",
// headers: {
// "Content-Type": "text/plain; charset=utf-8",
// "Content-Length": "11",
// },
// };
// const req = http.request(opts, (res) => {
// res.on("data", () => {});
// res.on("end", () => {
// abortController.abort();
// });
// assertEquals(res.statusCode, 200);
// assertEquals(requestHeaders.get("content-length"), "11");
// assertEquals(requestHeaders.has("transfer-encoding"), false);
// assertEquals(requestBody, "hello world");
// });
// req.on("socket", (socket) => {
// assert(socket.writable);
// assert(socket.readable);
// socket.setKeepAlive();
// socket.destroy();
// socket.setTimeout(100);
// });
// req.write("hello ");
// req.write("world");
// req.end();
const opts: RequestOptions = {
host: hostname,
port,
method: "POST",
headers: {
"Content-Type": "text/plain; charset=utf-8",
"Content-Length": "11",
},
};
const req = http.request(opts, (res) => {
res.on("data", () => {});
res.on("end", () => {
abortController.abort();
});
assertEquals(res.statusCode, 200);
assertEquals(requestHeaders.get("content-length"), "11");
assertEquals(requestHeaders.has("transfer-encoding"), false);
assertEquals(requestBody, "hello world");
});
req.on("socket", (socket) => {
assert(socket.writable);
assert(socket.readable);
socket.setKeepAlive();
socket.destroy();
socket.setTimeout(100);
});
req.write("hello ");
req.write("world");
req.end();
// await Promise.all([
// servePromise,
// // wait 100ms because of the socket.setTimeout(100) above
// // in order to not cause a flaky test sanitizer failure
// await new Promise((resolve) => setTimeout(resolve, 100)),
// ]);
// });
await Promise.all([
servePromise,
// wait 100ms because of the socket.setTimeout(100) above
// in order to not cause a flaky test sanitizer failure
await new Promise((resolve) => setTimeout(resolve, 100)),
]);
},
);
Deno.test("[node/http] send request with chunked body", async () => {
let requestHeaders: Headers;
@ -665,7 +670,9 @@ Deno.test("[node/http] server unref", async () => {
assertEquals(statusCode, 0);
});
Deno.test("[node/http] ClientRequest handle non-string headers", async () => {
Deno.test("[node/http] ClientRequest handle non-string headers", {
ignore: true,
}, async () => {
// deno-lint-ignore no-explicit-any
let headers: any;
const { promise, resolve, reject } = Promise.withResolvers<void>();
@ -687,7 +694,10 @@ Deno.test("[node/http] ClientRequest handle non-string headers", async () => {
assertEquals(headers!["1"], "2");
});
Deno.test("[node/http] ClientRequest uses HTTP/1.1", async () => {
Deno.test(
"[node/http] ClientRequest uses HTTP/1.1",
{ ignore: true },
async () => {
let body = "";
const { promise, resolve, reject } = Promise.withResolvers<void>();
const req = https.request("https://localhost:5545/http_version", {
@ -705,8 +715,10 @@ Deno.test("[node/http] ClientRequest uses HTTP/1.1", async () => {
req.once("error", (e) => reject(e));
req.end();
await promise;
console.log(body);
assertEquals(body, "HTTP/1.1");
});
},
);
Deno.test("[node/http] ClientRequest setTimeout", async () => {
let body = "";
@ -794,7 +806,10 @@ Deno.test("[node/http] ClientRequest PUT", async () => {
assertEquals(body, "hello world");
});
Deno.test("[node/http] ClientRequest search params", async () => {
Deno.test(
"[node/http] ClientRequest search params",
{ ignore: true },
async () => {
let body = "";
const { promise, resolve, reject } = Promise.withResolvers<void>();
const req = http.request({
@ -813,7 +828,8 @@ Deno.test("[node/http] ClientRequest search params", async () => {
req.end();
await promise;
assertEquals(body, "foo=bar");
});
},
);
Deno.test("[node/http] HTTPS server", async () => {
const deferred = Promise.withResolvers<void>();
@ -850,7 +866,7 @@ Deno.test("[node/http] HTTPS server", async () => {
Deno.test(
"[node/http] client upgrade",
{ permissions: { net: true } },
{ permissions: { net: true }, ignore: true },
async () => {
const { promise: serverClosed, resolve: resolveServer } = Promise
.withResolvers<void>();
@ -1009,6 +1025,7 @@ Deno.test(
Deno.test(
"[node/http] client destroy before sending request should not error",
{ ignore: true },
() => {
const request = http.request("http://localhost:5929/");
// Calling this would throw
@ -1018,6 +1035,7 @@ Deno.test(
Deno.test(
"[node/http] destroyed requests should not be sent",
{ ignore: true },
async () => {
let receivedRequest = false;
const server = Deno.serve(() => {
@ -1058,7 +1076,10 @@ Deno.test("[node/https] node:https exports globalAgent", async () => {
);
});
Deno.test("[node/http] node:http request.setHeader(header, null) doesn't throw", () => {
Deno.test(
"[node/http] node:http request.setHeader(header, null) doesn't throw",
{ ignore: true },
() => {
{
const req = http.request("http://localhost:4545/");
req.on("error", () => {});
@ -1075,7 +1096,8 @@ Deno.test("[node/http] node:http request.setHeader(header, null) doesn't throw",
req.end();
req.destroy();
}
});
},
);
Deno.test("[node/http] ServerResponse getHeader", async () => {
const { promise, resolve } = Promise.withResolvers<void>();
@ -1415,7 +1437,9 @@ Deno.test("[node/http] client closing a streaming request doesn't terminate serv
clearInterval(interval!);
});
Deno.test("[node/http] http.request() post streaming body works", async () => {
Deno.test("[node/http] http.request() post streaming body works", {
ignore: true,
}, async () => {
const server = http.createServer((req, res) => {
if (req.method === "POST") {
let receivedBytes = 0;
@ -1608,7 +1632,10 @@ Deno.test("[node/http] In ClientRequest, option.hostname has precedence over opt
await responseReceived.promise;
});
Deno.test("[node/http] upgraded socket closes when the server closed without closing handshake", async () => {
Deno.test(
"[node/http] upgraded socket closes when the server closed without closing handshake",
{ ignore: true },
async () => {
const clientSocketClosed = Promise.withResolvers<void>();
const serverProcessClosed = Promise.withResolvers<void>();
@ -1673,4 +1700,5 @@ Deno.test("[node/http] upgraded socket closes when the server closed without clo
await clientSocketClosed.promise;
await serverProcessClosed.promise;
});
},
);