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

Commit 7c1134b

Browse files
committed
Add a test for http2
1 parent ed7fcef commit 7c1134b

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

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

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

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

3132
const VERSION = process.versions.node;
3233

@@ -123,9 +124,8 @@ describe('Http2Plugin', () => {
123124
const serverPort = 8080;
124125
const serverPort2 = 8081;
125126
const host = `localhost:${serverPort}`;
126-
const host2 = `localhost:${serverPort2}`;
127127
const authority = `http://${host}`;
128-
const authority2 = `http://${host2}`;
128+
const authorityUrlObject = new URL('/', `http://${host}/`);
129129

130130
const log = logger.logger();
131131
const tracer = new CoreTracer();
@@ -161,7 +161,7 @@ describe('Http2Plugin', () => {
161161
server2.listen(serverPort2);
162162

163163
client = http2.connect(authority);
164-
client2 = http2.connect(authority2);
164+
client2 = http2.connect(authorityUrlObject);
165165
});
166166

167167
beforeEach(() => {
@@ -200,6 +200,24 @@ describe('Http2Plugin', () => {
200200
});
201201
});
202202

203+
it('should succeed when the client is connected using the url.URL object (#640)', async () => {
204+
const statusCode = 200;
205+
const testPath = `/${statusCode}`;
206+
const requestOptions = {
207+
':method': 'GET',
208+
':path': testPath,
209+
};
210+
211+
assert.strictEqual(spanVerifier.endedSpans.length, 0);
212+
213+
await http2Request.get(client2, requestOptions).then(result => {
214+
assert.strictEqual(result, statusCode.toString());
215+
assert.strictEqual(spanVerifier.endedSpans.length, 2);
216+
const span = spanVerifier.endedSpans[1];
217+
assertSpanAttributes(span, statusCode, 'GET', host, testPath);
218+
});
219+
});
220+
203221
const httpErrorCodes = [400, 401, 403, 404, 429, 501, 503, 504, 500];
204222

205223
httpErrorCodes.map(errorCode => {

0 commit comments

Comments
 (0)