Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bluetooth-low-energy): add health indicator for advertisement ti…
…meouts
- Loading branch information
Showing
4 changed files
with
111 additions
and
69 deletions.
There are no files selected for viewing
51 changes: 32 additions & 19 deletions
51
src/integration-support/bluetooth/bluetooth.health.spec.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 |
---|---|---|
@@ -1,35 +1,48 @@ | ||
import { BluetoothHealthIndicator } from './bluetooth.health'; | ||
import { HealthCheckError } from '@nestjs/terminus'; | ||
import { BluetoothService } from './bluetooth.service'; | ||
|
||
describe('BluetoothHealthIndicator', () => { | ||
let healthIndicator: BluetoothHealthIndicator; | ||
let mockBluetoothService: any; | ||
|
||
beforeEach(() => { | ||
healthIndicator = new BluetoothHealthIndicator(); | ||
mockBluetoothService = { | ||
successiveErrorsOccurred: 0, | ||
timeSinceLastDiscovery: null, | ||
} as BluetoothService; | ||
healthIndicator = new BluetoothHealthIndicator(mockBluetoothService); | ||
}); | ||
|
||
it('should report healthy by default', () => { | ||
const result = healthIndicator.successiveErrorCheck(3); | ||
expect(result['bt_successive_errors'].status).toEqual('up'); | ||
}); | ||
describe('ble_advertisement_timeout', () => { | ||
it('should report healthy by default', () => { | ||
const result = healthIndicator.lowEnergyAdvertisementTimeoutCheck( | ||
2 * 60 * 1000 | ||
); | ||
expect(result['ble_advertisement_timeout'].status).toEqual('up'); | ||
}); | ||
|
||
it('should report unhealthy after meeting the threshold', () => { | ||
healthIndicator.reportError(); | ||
healthIndicator.reportError(); | ||
healthIndicator.reportError(); | ||
it('should report unhealthy after meeting the threshold', () => { | ||
mockBluetoothService.timeSinceLastDiscovery = 120000; | ||
|
||
expect(() => healthIndicator.successiveErrorCheck(3)).toThrow( | ||
HealthCheckError | ||
); | ||
expect(() => | ||
healthIndicator.lowEnergyAdvertisementTimeoutCheck(2 * 60 * 1000) | ||
).toThrow(HealthCheckError); | ||
}); | ||
}); | ||
|
||
it('should reset the error count on success', () => { | ||
healthIndicator.reportError(); | ||
healthIndicator.reportError(); | ||
healthIndicator.reportError(); | ||
healthIndicator.reportSuccess(); | ||
describe('bt_successive_errors', () => { | ||
it('should report healthy by default', () => { | ||
const result = healthIndicator.successiveErrorCheck(3); | ||
expect(result['bt_successive_errors'].status).toEqual('up'); | ||
}); | ||
|
||
it('should report unhealthy after meeting the threshold', () => { | ||
mockBluetoothService.successiveErrorsOccurred = 3; | ||
|
||
const result = healthIndicator.successiveErrorCheck(3); | ||
expect(result['bt_successive_errors'].status).toEqual('up'); | ||
expect(() => healthIndicator.successiveErrorCheck(3)).toThrow( | ||
HealthCheckError | ||
); | ||
}); | ||
}); | ||
}); |
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
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
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