summaryrefslogtreecommitdiff
path: root/benchmark/http/http_server_for_chunky_client.js
blob: ef0a23a02928ef92b7bfe8748730f62b73dbc9cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use strict';

const assert = require('assert');
const http = require('http');
const { fork } = require('child_process');
const common = require('../common.js');
const { PIPE } = require('../../test/common');
const tmpdir = require('../../test/common/tmpdir');
process.env.PIPE_NAME = PIPE;

tmpdir.refresh();

const server = http.createServer((req, res) => {
  const headers = {
    'content-type': 'text/plain',
    'content-length': '2'
  };
  res.writeHead(200, headers);
  res.end('ok');
});

server.on('error', (err) => {
  throw new Error(`server error: ${err}`);
});
server.listen(PIPE);

const child = fork(
  `${__dirname}/_chunky_http_client.js`,
  process.argv.slice(2)
);
child.on('message', common.sendResult);
child.on('close', (code) => {
  server.close();
  assert.strictEqual(code, 0);
});