Skip to content

Commit

Permalink
Add HTTP/1 and HTTP/2 timings tests (#1957)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
etnbrd and sindresorhus committed Jan 5, 2022
1 parent 2ac07e1 commit 236e744
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions test/timings.ts
@@ -0,0 +1,53 @@
import test from 'ava';
import got from '../source/index.js';
import withServer from './helpers/with-server.js';

test('http/1 timings', withServer, async (t, server, got) => {
server.get('/', (_request, response) => {
response.end('ok');
});

const {timings} = await got('');

t.true(timings.start >= 0);
t.true(timings.socket! >= 0);
t.true(timings.lookup! >= 0);
t.true(timings.connect! >= 0);
t.true(timings.upload! >= 0);
t.true(timings.response! >= 0);
t.true(timings.end! >= 0);

const {phases} = timings;

t.true(phases.wait! >= 0);
t.true(phases.dns! >= 0);
t.true(phases.tcp! >= 0);
t.true(phases.request! >= 0);
t.true(phases.firstByte! >= 0);
t.true(phases.download! >= 0);
t.true(phases.total! >= 0);
});

test.failing('http/2 timings', async t => {
const {timings} = await got('https://httpbin.org/anything', {http2: true});

t.true(timings.start >= 0);
t.true(timings.socket! >= 0);
t.true(timings.lookup! >= 0);
t.true(timings.connect! >= 0);
t.true(timings.secureConnect! >= 0);
t.true(timings.upload! >= 0);
t.true(timings.response! >= 0);
t.true(timings.end! >= 0);

const {phases} = timings;

t.true(phases.wait! >= 0);
t.true(phases.dns! >= 0);
t.true(phases.tcp! >= 0);
t.true(phases.tls! >= 0);
t.true(phases.request! >= 0);
t.true(phases.firstByte! >= 0);
t.true(phases.download! >= 0);
t.true(phases.total! >= 0);
});

0 comments on commit 236e744

Please sign in to comment.