Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
Add a test for http2
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneDot committed Aug 22, 2019
1 parent de29571 commit 7f18437
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/opencensus-instrumentation-http2/test/test-http2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import * as semver from 'semver';

import { plugin } from '../src/';
import { Http2Plugin } from '../src/';
import { URL } from 'url';

const VERSION = process.versions.node;

Expand Down Expand Up @@ -101,9 +102,11 @@ describe('Http2Plugin', () => {

let server: http2.Http2Server;
let client: http2.ClientHttp2Session;
let client2: http2.ClientHttp2Session;
const serverPort = 8080;
const host = `localhost:${serverPort}`;
const authority = `http://${host}`;
const authorityUrlObject = new URL('/', `http://${host}/`);

const log = logger.logger();
const tracer = new CoreTracer();
Expand Down Expand Up @@ -131,6 +134,7 @@ describe('Http2Plugin', () => {
server.listen(serverPort);

client = http2.connect(authority);
client2 = http2.connect(authorityUrlObject);
});

beforeEach(() => {
Expand All @@ -140,6 +144,7 @@ describe('Http2Plugin', () => {
after(() => {
server.close();
client.destroy();
client2.destroy();
});

/** Should intercept outgoing requests */
Expand Down Expand Up @@ -167,6 +172,24 @@ describe('Http2Plugin', () => {
});
});

it('should succeed when the client is connected using the url.URL object (#640)', async () => {
const statusCode = 200;
const testPath = `/${statusCode}`;
const requestOptions = {
':method': 'GET',
':path': testPath,
};

assert.strictEqual(spanVerifier.endedSpans.length, 0);

await http2Request.get(client2, requestOptions).then(result => {
assert.strictEqual(result, statusCode.toString());
assert.strictEqual(spanVerifier.endedSpans.length, 2);
const span = spanVerifier.endedSpans[1];
assertSpanAttributes(span, statusCode, 'GET', host, testPath);
});
});

const httpErrorCodes = [400, 401, 403, 404, 429, 501, 503, 504, 500];

httpErrorCodes.map(errorCode => {
Expand Down

0 comments on commit 7f18437

Please sign in to comment.