From a23065f480012a836001045045c86826de6c2ead Mon Sep 17 00:00:00 2001 From: Heiko Rothe Date: Sun, 4 Oct 2020 20:37:46 +0200 Subject: [PATCH] fix(bluetooth-classic): fix health indicator when device not in reach A low scan time limit previously caused the health indicator to fail wrongly when the scanned device was not in reach. Closes #284 --- .../bluetooth-classic.service.spec.ts | 10 ++++++++++ .../bluetooth-classic/bluetooth-classic.service.ts | 9 +++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/integrations/bluetooth-classic/bluetooth-classic.service.spec.ts b/src/integrations/bluetooth-classic/bluetooth-classic.service.spec.ts index dd070d3a..77ddda6c 100644 --- a/src/integrations/bluetooth-classic/bluetooth-classic.service.spec.ts +++ b/src/integrations/bluetooth-classic/bluetooth-classic.service.spec.ts @@ -778,4 +778,14 @@ Requesting information ... expect(healthIndicator.reportSuccess).not.toHaveBeenCalled(); expect(healthIndicator.reportError).not.toHaveBeenCalled(); }); + + it('should not report an error if the scan was stopped due to low time limits', async () => { + mockExec.mockRejectedValue({ + message: 'killed', + signal: 'SIGKILL', + }); + await service.inquireRssi(''); + + expect(healthIndicator.reportError).not.toHaveBeenCalled(); + }); }); diff --git a/src/integrations/bluetooth-classic/bluetooth-classic.service.ts b/src/integrations/bluetooth-classic/bluetooth-classic.service.ts index a624fc8b..69c3bb0e 100644 --- a/src/integrations/bluetooth-classic/bluetooth-classic.service.ts +++ b/src/integrations/bluetooth-classic/bluetooth-classic.service.ts @@ -34,7 +34,8 @@ import { BluetoothClassicHealthIndicator } from './bluetooth-classic.health'; const execPromise = util.promisify(exec); @Injectable() -export class BluetoothClassicService extends KalmanFilterable(Object, 1.4, 1) +export class BluetoothClassicService + extends KalmanFilterable(Object, 1.4, 1) implements OnModuleInit, OnApplicationBootstrap { private readonly config: BluetoothClassicConfig; private rotationOffset = 0; @@ -225,8 +226,12 @@ export class BluetoothClassicService extends KalmanFilterable(Object, 1.4, 1) this.logger.debug( `Query of ${address} reached scan time limit, resetting hci${this.config.hciDeviceId}` ); - this.healthIndicator.reportError(); this.resetHciDevice(); + + // when not reachable a scan runs for 6s, so lower time limits might not be an error + if (this.config.scanTimeLimit >= 6) { + this.healthIndicator.reportError(); + } } else if ( e.message?.includes('Input/output') || e.message?.includes('I/O')