Skip to content

Commit

Permalink
capture non-200 status codes in the tcp test as failures
Browse files Browse the repository at this point in the history
  • Loading branch information
Stono committed Jul 6, 2020
1 parent 2003c38 commit a6c05b6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/tester/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export default class Tester implements ITester {
source: this.me,
destination: agent,
timings: result.timings,
result: 'pass'
result: result.statusCode === 200 ? 'pass' : 'fail'
}
this.metrics.handleTCPTestResult(mappedResult)
return mappedResult
Expand Down
30 changes: 29 additions & 1 deletion test/tester.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('Tester', () => {
should(result[0].result).eql('pass')
})

it('should should capture a failed ping as an error', async () => {
it('should should capture a failed ping as an fail', async () => {
const udpClient = td.object<IUDPClient>()
const udpPingResult = td.object<IUDPPingResult>()
udpPingResult.success = true
Expand Down Expand Up @@ -92,4 +92,32 @@ describe('Tester', () => {
const result = await sut.runTCPTests([agent])
should(result[0].result).eql('pass')
})

it('should capture a 5xx code as a fail', async () => {
td.when(
got('http://127.0.0.1:8080/readiness', { timeout: 500 })
).thenResolve({ statusCode: 500 })

const agent = td.object<IAgent>()
agent.ip = '127.0.0.1'
agent.name = 'local'
agent.nodeName = 'some-node'
agent.zone = 'some-zone'
const result = await sut.runTCPTests([agent])
should(result[0].result).eql('fail')
})

it('should capture a failed tcp test as a fail', async () => {
td.when(
got('http://127.0.0.1:8080/readiness', { timeout: 500 })
).thenReject(new Error('boom'))

const agent = td.object<IAgent>()
agent.ip = '127.0.0.1'
agent.name = 'local'
agent.nodeName = 'some-node'
agent.zone = 'some-zone'
const result = await sut.runTCPTests([agent])
should(result[0].result).eql('fail')
})
})

0 comments on commit a6c05b6

Please sign in to comment.