-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(appmesh): eagerly validate
healthCheck
settings (#4221)
* feat(appmesh): throw if healthCheck thresholds aren't met * feat(appmesh): throw if healthCheck path with Protocol.TCP * chore: tslint fix * chore: better threshold hint * fix: check isUnresolved * chore: remove trailing whitespace
- Loading branch information
1 parent
eb0a269
commit 84a1b45
Showing
2 changed files
with
169 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
packages/@aws-cdk/aws-appmesh/test/test.health-check.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import cdk = require('@aws-cdk/core'); | ||
import {Test} from 'nodeunit'; | ||
|
||
import appmesh = require('../lib'); | ||
|
||
let idCounter = 0; | ||
const getNode = (stack: cdk.Stack) => { | ||
const mesh = new appmesh.Mesh(stack, `mesh-${++idCounter}`, { | ||
meshName: 'test-mesh', | ||
}); | ||
return mesh.addVirtualNode(`virtual-node-${idCounter}`, { | ||
dnsHostName: 'test-node', | ||
}); | ||
}; | ||
|
||
export = { | ||
'interval'(test: Test) { | ||
// GIVEN | ||
const stack = new cdk.Stack(); | ||
|
||
const [min, max] = [5000, 300000]; | ||
|
||
// WHEN | ||
const toThrow = (millis: number) => getNode(stack).addListeners({ | ||
healthCheck: {interval: cdk.Duration.millis(millis)} | ||
}); | ||
|
||
// THEN | ||
test.doesNotThrow(() => toThrow(min)); | ||
test.doesNotThrow(() => toThrow(max)); | ||
test.throws(() => toThrow(min - 1), /below the minimum threshold/); | ||
test.throws(() => toThrow(max + 1), /above the maximum threshold/); | ||
|
||
test.done(); | ||
}, | ||
'timeout'(test: Test) { | ||
// GIVEN | ||
const stack = new cdk.Stack(); | ||
|
||
const [min, max] = [2000, 60000]; | ||
|
||
// WHEN | ||
const toThrow = (millis: number) => getNode(stack).addListeners({ | ||
healthCheck: {timeout: cdk.Duration.millis(millis)} | ||
}); | ||
|
||
// THEN | ||
test.doesNotThrow(() => toThrow(min)); | ||
test.doesNotThrow(() => toThrow(max)); | ||
test.throws(() => toThrow(min - 1), /below the minimum threshold/); | ||
test.throws(() => toThrow(max + 1), /above the maximum threshold/); | ||
|
||
test.done(); | ||
}, | ||
'port'(test: Test) { | ||
// GIVEN | ||
const stack = new cdk.Stack(); | ||
|
||
const [min, max] = [1, 65535]; | ||
|
||
// WHEN | ||
const toThrow = (port: number) => getNode(stack).addListeners({ | ||
healthCheck: {port} | ||
}); | ||
|
||
// THEN | ||
test.doesNotThrow(() => toThrow(min)); | ||
test.doesNotThrow(() => toThrow(max)); | ||
// falsy, falls back to portMapping.port | ||
// test.throws(() => toThrow(min - 1), /below the minimum threshold/); | ||
test.throws(() => toThrow(max + 1), /above the maximum threshold/); | ||
|
||
test.done(); | ||
}, | ||
'healthyThreshold'(test: Test) { | ||
// GIVEN | ||
const stack = new cdk.Stack(); | ||
|
||
const [min, max] = [2, 10]; | ||
|
||
// WHEN | ||
const toThrow = (healthyThreshold: number) => getNode(stack).addListeners({ | ||
healthCheck: {healthyThreshold} | ||
}); | ||
|
||
// THEN | ||
test.doesNotThrow(() => toThrow(min)); | ||
test.doesNotThrow(() => toThrow(max)); | ||
test.throws(() => toThrow(min - 1), /below the minimum threshold/); | ||
test.throws(() => toThrow(max + 1), /above the maximum threshold/); | ||
|
||
test.done(); | ||
}, | ||
'unhealthyThreshold'(test: Test) { | ||
// GIVEN | ||
const stack = new cdk.Stack(); | ||
|
||
const [min, max] = [2, 10]; | ||
|
||
// WHEN | ||
const toThrow = (unhealthyThreshold: number) => getNode(stack).addListeners({ | ||
healthCheck: {unhealthyThreshold} | ||
}); | ||
|
||
// THEN | ||
test.doesNotThrow(() => toThrow(min)); | ||
test.doesNotThrow(() => toThrow(max)); | ||
test.throws(() => toThrow(min - 1), /below the minimum threshold/); | ||
test.throws(() => toThrow(max + 1), /above the maximum threshold/); | ||
|
||
test.done(); | ||
}, | ||
'throws if path and Protocol.TCP'(test: Test) { | ||
// GIVEN | ||
const stack = new cdk.Stack(); | ||
|
||
// WHEN | ||
const toThrow = (protocol: appmesh.Protocol) => getNode(stack).addListeners({ | ||
healthCheck: { | ||
protocol, | ||
path: '/' | ||
} | ||
}); | ||
|
||
// THEN | ||
test.doesNotThrow(() => toThrow(appmesh.Protocol.HTTP)); | ||
test.throws(() => toThrow(appmesh.Protocol.TCP), /The path property cannot be set with Protocol.TCP/); | ||
|
||
test.done(); | ||
}, | ||
}; |