MCPcopy Create free account
hub / github.com/nodejs/node / check

Function check

test/parallel/test-http-1.0-keep-alive.js:106–156  ·  view source on GitHub ↗
(tests)

Source from the content-addressed store, hash-verified

104}]);
105
106function check(tests) {
107 const test = tests[0];
108 let server;
109 if (test) {
110 server = http.createServer(serverHandler).listen(0, '127.0.0.1', client);
111 }
112 let current = 0;
113
114 function next() {
115 check(tests.slice(1));
116 }
117
118 function serverHandler(req, res) {
119 if (current + 1 === test.responses.length) this.close();
120 const ctx = test.responses[current];
121 console.error('< SERVER SENDING RESPONSE', ctx);
122 res.writeHead(200, ctx.headers);
123 ctx.chunks.slice(0, -1).forEach(function(chunk) { res.write(chunk); });
124 res.end(ctx.chunks[ctx.chunks.length - 1]);
125 }
126
127 function client() {
128 if (current === test.requests.length) return next();
129 const port = server.address().port;
130 const conn = net.createConnection(port, '127.0.0.1', connected);
131
132 function connected() {
133 const ctx = test.requests[current];
134 console.error(' > CLIENT SENDING REQUEST', ctx);
135 conn.setEncoding('utf8');
136 conn.write(ctx.data);
137
138 function onclose() {
139 console.error(' > CLIENT CLOSE');
140 if (!ctx.expectClose) throw new Error('unexpected close');
141 client();
142 }
143 conn.on('close', onclose);
144
145 function ondata(s) {
146 console.error(' > CLIENT ONDATA %j %j', s.length, s.toString());
147 current++;
148 if (ctx.expectClose) return;
149 conn.removeListener('close', onclose);
150 conn.removeListener('data', ondata);
151 connected();
152 }
153 conn.on('data', ondata);
154 }
155 }
156}

Callers 2

nextFunction · 0.70

Calls 1

listenMethod · 0.80

Tested by

no test coverage detected