From 7f1843780069f21c6f0f6116f67f62d93899118c Mon Sep 17 00:00:00 2001 From: Hiroaki Goto <1642211+StoneDot@users.noreply.github.com> Date: Thu, 22 Aug 2019 16:24:56 +0900 Subject: [PATCH] Add a test for http2 --- .../test/test-http2.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/opencensus-instrumentation-http2/test/test-http2.ts b/packages/opencensus-instrumentation-http2/test/test-http2.ts index 6658a813b..e9767e43c 100644 --- a/packages/opencensus-instrumentation-http2/test/test-http2.ts +++ b/packages/opencensus-instrumentation-http2/test/test-http2.ts @@ -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; @@ -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(); @@ -131,6 +134,7 @@ describe('Http2Plugin', () => { server.listen(serverPort); client = http2.connect(authority); + client2 = http2.connect(authorityUrlObject); }); beforeEach(() => { @@ -140,6 +144,7 @@ describe('Http2Plugin', () => { after(() => { server.close(); client.destroy(); + client2.destroy(); }); /** Should intercept outgoing requests */ @@ -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 => {