Skip to content

Commit

Permalink
Adding unit-tests which rely on non-public properties by abusing any
Browse files Browse the repository at this point in the history
  • Loading branch information
kobelb committed Jul 20, 2020
1 parent 9ce7c48 commit 5aba5fc
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/core/server/http/http_server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import { Server } from 'http';
import { readFileSync } from 'fs';
import supertest from 'supertest';
import { PassThrough } from 'stream';

import { ByteSizeValue, schema } from '@kbn/config-schema';
import { HttpConfig } from './http_config';
Expand Down Expand Up @@ -68,6 +69,7 @@ beforeEach(() => {
port: 10002,
ssl: { enabled: false },
compression: { enabled: true },
socketTimeout: 2000,
} as HttpConfig;

configWithSSL = {
Expand Down Expand Up @@ -992,6 +994,54 @@ describe('body options', () => {
});
});

describe('idle socket timeout', () => {
test('should set socket timeout based on the server timeout when not specified in the route', async () => {
const { registerRouter, server: innerServer } = await server.setup(config);

const router = new Router('', logger, enhanceWithContext);
router.get(
{
path: '/',
validate: { body: schema.any() },
},
(context, req, res) => {
// net.Socket::timeout isn't documented or part of the types, yet...
return res.ok({ body: { socketTimeout: (req.socket as any).socket.timeout } });
}
);
registerRouter(router);

await server.start();
await supertest(innerServer.listener).get('/').send().expect(200, {
socketTimeout: config.socketTimeout,
});
});

test('should set socket timeout when specified in the route', async () => {
const { registerRouter, server: innerServer } = await server.setup(config);

const routeIdleSocketTimeout = 12000;
const router = new Router('', logger, enhanceWithContext);
router.get(
{
path: '/',
validate: { body: schema.any() },
options: { timeout: { idleSocket: routeIdleSocketTimeout } },
},
(context, req, res) => {
// net.Socket::timeout isn't documented or part of the types, yet...
return res.ok({ body: { socketTimeout: (req.socket as any).socket.timeout } });
}
);
registerRouter(router);

await server.start();
await supertest(innerServer.listener).get('/').send().expect(200, {
socketTimeout: routeIdleSocketTimeout,
});
});
});

test('should return a stream in the body', async () => {
const { registerRouter, server: innerServer } = await server.setup(config);

Expand Down

0 comments on commit 5aba5fc

Please sign in to comment.