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

fix: fix timeout in aws resource detector #2186

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class AwsEc2Detector implements Detector {
const timeoutId = setTimeout(() => {
req.abort();
reject(new Error('EC2 metadata api request timed out.'));
}, 1000);
}, this.MILLISECOND_TIME_OUT);

const req = http.request(options, res => {
clearTimeout(timeoutId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ describe('awsEc2Detector', () => {
scope.done();
});

it('should throw when timed out', async () => {
it('should throw when timed out', function (done) {
this.timeout(7000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you're changing the timeout value for the test, you're not really testing the new value you changed to. Don't you want to test with the 5s?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the timeouts

const expectedError = new Error('EC2 metadata api request timed out.');
const scope = nock(AWS_HOST)
.put(AWS_TOKEN_PATH)
Expand All @@ -120,17 +121,21 @@ describe('awsEc2Detector', () => {
.reply(200, () => mockedIdentityResponse)
.get(AWS_HOST_PATH)
.matchHeader(AWS_METADATA_TOKEN_HEADER, mockedTokenResponse)
.delayConnection(2000)
.delayConnection(6000)
.reply(200, () => mockedHostResponse);

try {
await awsEc2Detector.detect();
assert.ok(false, 'Expected to throw');
} catch (err) {
assert.deepStrictEqual(err, expectedError);
}

scope.done();
awsEc2Detector
.detect()
.then(() => {
assert.ok(false, 'Expected to throw');
})
.catch(err => {
assert.deepStrictEqual(err, expectedError);
})
.finally(() => {
scope.done();
done();
});
});

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