Skip to content

Commit

Permalink
chore: address code review
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Feb 22, 2020
1 parent 7db521a commit 244a670
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ export function requestTimeout(): number {
// This logic detects a GCF environment, using the documented environment
// variables K_SERVICE and FUNCTION_NAME:
// https://cloud.google.com/functions/docs/env-var and, in a GCF environment
// extends timeouts signficantly (the 500,000ms value is based on testing
// 150 concurrent network connections.
return process.env.K_SERVICE || process.env.FUNCTION_NAME ? 500000 : 3000;
// eliminates timeouts (by setting the value to 0 to disable).
return process.env.K_SERVICE || process.env.FUNCTION_NAME ? 0 : 3000;
}
10 changes: 8 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,14 @@ it('returns request timeout of 3000ms, when not GCF', () => {
assert.strictEqual(gcp.requestTimeout(), 3000);
});

it('returns request timeout of 500000ms, when in GCF environment', () => {
it('returns request timeout of 0, when FUNCTION_NAME set', () => {
process.env.FUNCTION_NAME = 'my-function';
assert.strictEqual(gcp.requestTimeout(), 500000);
assert.strictEqual(gcp.requestTimeout(), 0);
delete process.env.FUNCTION_NAME;
});

it('returns request timeout of 0, when K_SERVICE set', () => {
process.env.K_SERVICE = 'my-function';
assert.strictEqual(gcp.requestTimeout(), 0);
delete process.env.K_SERVICE;
});

0 comments on commit 244a670

Please sign in to comment.