Skip to content

Commit 6ae88f3

Browse files
authored
Merge branch 'main' into docs/contributing-guidelines
2 parents 086a852 + 9e4726c commit 6ae88f3

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsEc2Detector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class AwsEc2Detector implements Detector {
131131
const timeoutId = setTimeout(() => {
132132
req.abort();
133133
reject(new Error('EC2 metadata api request timed out.'));
134-
}, 1000);
134+
}, this.MILLISECOND_TIME_OUT);
135135

136136
const req = http.request(options, res => {
137137
clearTimeout(timeoutId);

detectors/node/opentelemetry-resource-detector-aws/test/detectors/AwsEc2Detector.test.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ describe('awsEc2Detector', () => {
109109
scope.done();
110110
});
111111

112-
it('should throw when timed out', async () => {
112+
it('should throw when timed out', function (done) {
113+
this.timeout(6000);
113114
const expectedError = new Error('EC2 metadata api request timed out.');
114115
const scope = nock(AWS_HOST)
115116
.put(AWS_TOKEN_PATH)
@@ -120,17 +121,21 @@ describe('awsEc2Detector', () => {
120121
.reply(200, () => mockedIdentityResponse)
121122
.get(AWS_HOST_PATH)
122123
.matchHeader(AWS_METADATA_TOKEN_HEADER, mockedTokenResponse)
123-
.delayConnection(2000)
124+
.delayConnection(5000)
124125
.reply(200, () => mockedHostResponse);
125126

126-
try {
127-
await awsEc2Detector.detect();
128-
assert.ok(false, 'Expected to throw');
129-
} catch (err) {
130-
assert.deepStrictEqual(err, expectedError);
131-
}
132-
133-
scope.done();
127+
awsEc2Detector
128+
.detect()
129+
.then(() => {
130+
assert.ok(false, 'Expected to throw');
131+
})
132+
.catch(err => {
133+
assert.deepStrictEqual(err, expectedError);
134+
})
135+
.finally(() => {
136+
scope.done();
137+
done();
138+
});
134139
});
135140

136141
it('should throw when replied with an Error', async () => {

0 commit comments

Comments
 (0)