Skip to content

Commit 45edd40

Browse files
author
Marco Crespi
committed
chore: Fix parallel test
1 parent 16fbb91 commit 45edd40

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

tests/parallel.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { DbusMODblue } = require('../lib/dbus');
33
const { MacMODblue } = require('../lib/mac');
44
const { WinMODblue } = require('../lib/win');
55

6-
const MAC_ADDRESS = /(?:[0-9A-F]{2}:?){6}/i;
6+
const MAC_ADDRESS = /(?:[0-9a-f]{2}:?){6}/i;
77

88
const USAGE = `
99
Usage:
@@ -16,7 +16,10 @@ Arguments:
1616
`;
1717

1818
const BINDINGS = process.argv[2];
19-
const PERIPHERAL_ADDRESSES = (process.argv[3] || '').split(/[,|;]/g).filter((p) => !!p && MAC_ADDRESS.test(p));
19+
const PERIPHERAL_ADDRESSES = (process.argv[3] || '')
20+
.split(/[,|;]/g)
21+
.filter((p) => !!p && MAC_ADDRESS.test(p))
22+
.map((a) => a.toLowerCase());
2023
const SERVICE_UUID = process.argv[4];
2124
const CHAR_UUID = process.argv[5];
2225

@@ -62,26 +65,19 @@ const main = async () => {
6265
// Scan for 3 seconds
6366
await new Promise((resolve) => setTimeout(resolve, 3000));
6467

65-
await adapter.stopScanning();
66-
6768
console.log('Getting peripherals...');
6869

69-
const peripherals = await adapter.getScannedPeripherals();
70-
const missing = PERIPHERAL_ADDRESSES.filter(
71-
(address) => !peripherals.some((p) => p.address === address.toUpperCase())
72-
);
73-
if (missing.length > 0) {
74-
throw new Error(
75-
`Could not find peripherals.\nAvailable: ${peripherals.map((p) => p.address)}\nMissing: ${missing}`
76-
);
77-
}
78-
7970
console.time('Connect');
8071
let total = 0;
8172
let success = 0;
8273

8374
const testDevice = async (targetAddress) => {
75+
const peripherals = await adapter.getScannedPeripherals();
8476
const peripheral = peripherals.find((p) => p.address === targetAddress);
77+
if (!peripheral) {
78+
throw new Error(`Missing peripheral ${targetAddress}`);
79+
}
80+
8581
console.log(targetAddress, `Connecting ${total}...`);
8682

8783
try {
@@ -127,8 +123,8 @@ const main = async () => {
127123
};
128124

129125
for (let i = 0; i < PERIPHERAL_ADDRESSES.length; i++) {
130-
testDevice(PERIPHERAL_ADDRESSES[i].toUpperCase());
131-
setInterval(() => testDevice(PERIPHERAL_ADDRESSES[i].toUpperCase()), 10000);
126+
testDevice(PERIPHERAL_ADDRESSES[i]);
127+
setInterval(() => testDevice(PERIPHERAL_ADDRESSES[i]), 10000);
132128
}
133129

134130
// Keep this process running

0 commit comments

Comments
 (0)