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

Commit 7f18437

Browse files
committed
Add a test for http2
1 parent de29571 commit 7f18437

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

packages/opencensus-instrumentation-http2/test/test-http2.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import * as semver from 'semver';
2727

2828
import { plugin } from '../src/';
2929
import { Http2Plugin } from '../src/';
30+
import { URL } from 'url';
3031

3132
const VERSION = process.versions.node;
3233

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

102103
let server: http2.Http2Server;
103104
let client: http2.ClientHttp2Session;
105+
let client2: http2.ClientHttp2Session;
104106
const serverPort = 8080;
105107
const host = `localhost:${serverPort}`;
106108
const authority = `http://${host}`;
109+
const authorityUrlObject = new URL('/', `http://${host}/`);
107110

108111
const log = logger.logger();
109112
const tracer = new CoreTracer();
@@ -131,6 +134,7 @@ describe('Http2Plugin', () => {
131134
server.listen(serverPort);
132135

133136
client = http2.connect(authority);
137+
client2 = http2.connect(authorityUrlObject);
134138
});
135139

136140
beforeEach(() => {
@@ -140,6 +144,7 @@ describe('Http2Plugin', () => {
140144
after(() => {
141145
server.close();
142146
client.destroy();
147+
client2.destroy();
143148
});
144149

145150
/** Should intercept outgoing requests */
@@ -167,6 +172,24 @@ describe('Http2Plugin', () => {
167172
});
168173
});
169174

175+
it('should succeed when the client is connected using the url.URL object (#640)', async () => {
176+
const statusCode = 200;
177+
const testPath = `/${statusCode}`;
178+
const requestOptions = {
179+
':method': 'GET',
180+
':path': testPath,
181+
};
182+
183+
assert.strictEqual(spanVerifier.endedSpans.length, 0);
184+
185+
await http2Request.get(client2, requestOptions).then(result => {
186+
assert.strictEqual(result, statusCode.toString());
187+
assert.strictEqual(spanVerifier.endedSpans.length, 2);
188+
const span = spanVerifier.endedSpans[1];
189+
assertSpanAttributes(span, statusCode, 'GET', host, testPath);
190+
});
191+
});
192+
170193
const httpErrorCodes = [400, 401, 403, 404, 429, 501, 503, 504, 500];
171194

172195
httpErrorCodes.map(errorCode => {

0 commit comments

Comments
 (0)