Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Update nock version and migrate broken tests #1504

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/opentelemetry-exporter-jaeger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"codecov": "3.7.2",
"gts": "2.0.2",
"mocha": "7.2.0",
"nock": "12.0.3",
"nock": "13.0.4",
"nyc": "15.1.0",
"rimraf": "3.0.2",
"ts-mocha": "7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-exporter-zipkin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"karma-spec-reporter": "0.0.32",
"karma-webpack": "4.0.2",
"mocha": "7.2.0",
"nock": "12.0.3",
"nock": "13.0.4",
"nyc": "15.1.0",
"rimraf": "3.0.2",
"sinon": "9.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-plugin-http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"got": "9.6.0",
"gts": "2.0.2",
"mocha": "7.2.0",
"nock": "12.0.3",
"nock": "13.0.4",
"nyc": "15.1.0",
"request": "2.88.2",
"request-promise-native": "1.0.9",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,80 +606,92 @@ describe('HttpPlugin', () => {
}
});

it('should have 1 ended span when request is aborted', async () => {
nock(`${protocol}://my.server.com`)
.get('/')
.socketDelay(50)
.reply(200, '<html></html>');

const promiseRequest = new Promise((resolve, reject) => {
const req = http.request(
`${protocol}://my.server.com`,
(resp: http.IncomingMessage) => {
let data = '';
resp.on('data', chunk => {
data += chunk;
});
resp.on('end', () => {
resolve(data);
describe('when request is aborted', () => {
describe('before the connection succeeds', () => {
it('should have 1 ended span', async () => {
nock(`${protocol}://my.server.com`)
.get('/')
.delayConnection(50)
.reply(200, '<html></html>');

const promiseRequest = new Promise((resolve, reject) => {
const req = http.request(
`${protocol}://my.server.com`,
(resp: http.IncomingMessage) => {
let data = '';
resp.on('data', chunk => {
data += chunk;
});
resp.on('end', () => {
resolve(data);
});
}
);
req.setTimeout(10, () => {
req.abort();
reject('timeout');
});
return req.end();
});

try {
await promiseRequest;
assert.fail();
} catch (error) {
const spans = memoryExporter.getFinishedSpans();
const [span] = spans;
assert.strictEqual(spans.length, 1);
assert.strictEqual(span.status.code, CanonicalCode.ABORTED);
assert.ok(Object.keys(span.attributes).length >= 6);
}
);
req.setTimeout(10, () => {
req.abort();
reject('timeout');
});
return req.end();
});

try {
await promiseRequest;
assert.fail();
} catch (error) {
const spans = memoryExporter.getFinishedSpans();
const [span] = spans;
assert.strictEqual(spans.length, 1);
assert.strictEqual(span.status.code, CanonicalCode.ABORTED);
assert.ok(Object.keys(span.attributes).length >= 6);
}
});
describe('after the response is received', () => {
let altServer: http.Server;
const altServerPort = 22346;

it('should have 1 ended span when request is aborted after receiving response', async () => {
nock(`${protocol}://my.server.com`)
.get('/')
.delay({
body: 50,
})
.replyWithFile(200, `${process.cwd()}/package.json`);
beforeEach(done => {
altServer = http.createServer((request, response) => {
response.write('First part of the response');
setTimeout(() => response.end(), 50);
});
altServer.listen(altServerPort, done);
});

const promiseRequest = new Promise((resolve, reject) => {
const req = http.request(
`${protocol}://my.server.com`,
(resp: http.IncomingMessage) => {
let data = '';
resp.on('data', chunk => {
req.abort();
data += chunk;
});
resp.on('end', () => {
resolve(data);
});
}
);
afterEach(() => {
altServer.close();
});

return req.end();
});
it('should have 1 ended span', async () => {
const promiseRequest = new Promise((resolve, reject) => {
const req = http.request(
`${protocol}://${hostname}:${altServerPort}`,
(resp: http.IncomingMessage) => {
resp.on('data', data => {
req.abort();
});
resp.on('close', () => {
resolve();
});
}
);

try {
await promiseRequest;
assert.fail();
} catch (error) {
const spans = memoryExporter.getFinishedSpans();
const [span] = spans;
assert.strictEqual(spans.length, 1);
assert.strictEqual(span.status.code, CanonicalCode.ABORTED);
assert.ok(Object.keys(span.attributes).length > 7);
}
return req.end();
});

try {
await promiseRequest;
assert.fail();
} catch (error) {
const spans = memoryExporter.getFinishedSpans();
const [span] = spans;
assert.strictEqual(spans.length, 1);
assert.strictEqual(span.status.code, CanonicalCode.ABORTED);
assert.ok(Object.keys(span.attributes).length > 7);
}
});
});
});

it("should have 1 ended span when request doesn't listening response", done => {
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-plugin-https/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"got": "9.6.0",
"gts": "2.0.2",
"mocha": "7.2.0",
"nock": "12.0.3",
"nock": "13.0.4",
"nyc": "15.1.0",
"request": "2.88.2",
"request-promise-native": "1.0.9",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,80 +598,98 @@ describe('HttpsPlugin', () => {
}
});

it('should have 1 ended span when request is aborted', async () => {
nock(`${protocol}://my.server.com`)
.get('/')
.socketDelay(50)
.reply(200, '<html></html>');

const promiseRequest = new Promise((resolve, reject) => {
const req = https.request(
`${protocol}://my.server.com`,
(resp: http.IncomingMessage) => {
let data = '';
resp.on('data', chunk => {
data += chunk;
});
resp.on('end', () => {
resolve(data);
describe('when request is aborted', () => {
describe('before the connection succeeds', () => {
it('should have 1 ended span', async () => {
nock(`${protocol}://my.server.com`)
.get('/')
.delayConnection(50)
.reply(200, '<html></html>');

const promiseRequest = new Promise((resolve, reject) => {
const req = https.request(
`${protocol}://my.server.com`,
(resp: http.IncomingMessage) => {
let data = '';
resp.on('data', chunk => {
data += chunk;
});
resp.on('end', () => {
resolve(data);
});
}
);
req.setTimeout(10, () => {
req.abort();
reject('timeout');
});
return req.end();
});

try {
await promiseRequest;
assert.fail();
} catch (error) {
const spans = memoryExporter.getFinishedSpans();
const [span] = spans;
assert.strictEqual(spans.length, 1);
assert.strictEqual(span.status.code, CanonicalCode.ABORTED);
assert.ok(Object.keys(span.attributes).length >= 6);
}
);
req.setTimeout(10, () => {
req.abort();
reject('timeout');
});
return req.end();
});

try {
await promiseRequest;
assert.fail();
} catch (error) {
const spans = memoryExporter.getFinishedSpans();
const [span] = spans;
assert.strictEqual(spans.length, 1);
assert.strictEqual(span.status.code, CanonicalCode.ABORTED);
assert.ok(Object.keys(span.attributes).length >= 6);
}
});
describe('after the response is received', () => {
let altServer: http.Server;
const altServerPort = 22346;

beforeEach(done => {
altServer = https.createServer(
{
key: fs.readFileSync('test/fixtures/server-key.pem'),
cert: fs.readFileSync('test/fixtures/server-cert.pem'),
},
(request, response) => {
response.write('First part of the response');
setTimeout(() => response.end(), 50);
}
);
altServer.listen(altServerPort, done);
});

it('should have 1 ended span when request is aborted after receiving response', async () => {
nock(`${protocol}://my.server.com`)
.get('/')
.delay({
body: 50,
})
.replyWithFile(200, `${process.cwd()}/package.json`);
afterEach(() => {
altServer.close();
});

const promiseRequest = new Promise((resolve, reject) => {
const req = https.request(
`${protocol}://my.server.com`,
(resp: http.IncomingMessage) => {
let data = '';
resp.on('data', chunk => {
req.abort();
data += chunk;
});
resp.on('end', () => {
resolve(data);
});
it('should have 1 ended span', async () => {
const promiseRequest = new Promise((resolve, reject) => {
const req = https.request(
`${protocol}://${hostname}:${altServerPort}`,
(resp: http.IncomingMessage) => {
resp.on('data', data => {
req.abort();
});
resp.on('close', () => {
resolve();
});
}
);

return req.end();
});

try {
await promiseRequest;
assert.fail();
} catch (error) {
const spans = memoryExporter.getFinishedSpans();
const [span] = spans;
assert.strictEqual(spans.length, 1);
assert.strictEqual(span.status.code, CanonicalCode.ABORTED);
assert.ok(Object.keys(span.attributes).length > 7);
}
);

return req.end();
});
});

try {
await promiseRequest;
assert.fail();
} catch (error) {
const spans = memoryExporter.getFinishedSpans();
const [span] = spans;
assert.strictEqual(spans.length, 1);
assert.strictEqual(span.status.code, CanonicalCode.ABORTED);
assert.ok(Object.keys(span.attributes).length > 7);
}
});

it("should have 1 ended span when response is listened by using req.on('response')", done => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"codecov": "3.7.2",
"gts": "2.0.2",
"mocha": "7.2.0",
"nock": "12.0.3",
"nock": "13.0.4",
"nyc": "15.1.0",
"rimraf": "3.0.2",
"sinon": "9.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"codecov": "3.7.2",
"gts": "2.0.2",
"mocha": "7.2.0",
"nock": "12.0.3",
"nock": "13.0.4",
"nyc": "15.1.0",
"rimraf": "3.0.2",
"ts-mocha": "7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-resources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"codecov": "3.7.2",
"gts": "2.0.2",
"mocha": "7.2.0",
"nock": "12.0.3",
"nock": "13.0.4",
"nyc": "15.1.0",
"rimraf": "3.0.2",
"sinon": "9.0.3",
Expand Down
Loading