Skip to content

Commit ec40408

Browse files
kriszypclaude
andcommitted
test: migrate MQTT test to setupHarperWithFixture
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent f898b7e commit ec40408

1 file changed

Lines changed: 2 additions & 46 deletions

File tree

integrationTests/mqtt/mqtt.test.ts

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ import { resolve } from 'node:path';
1919

2020
import mqtt, { type IClientOptions, type MqttClient } from 'mqtt';
2121

22-
import { startHarper, teardownHarper, sendOperation, type ContextWithHarper } from '@harperfast/integration-testing';
22+
import { setupHarperWithFixture, teardownHarper, type ContextWithHarper } from '@harperfast/integration-testing';
2323

24-
const PROJECT = 'mqtt-user-sub';
2524
const FIXTURE_PATH = resolve(import.meta.dirname, 'fixtures/mqtt-user-sub');
2625

2726
let MQTT_URL = '';
@@ -258,54 +257,11 @@ suite(
258257
{ skip: skipSuite },
259258
(ctx: ContextWithHarper) => {
260259
before(async () => {
261-
await startHarper(ctx);
260+
await setupHarperWithFixture(ctx, FIXTURE_PATH, { config: {}, env: {} });
262261

263262
const httpURL = ctx.harper.httpURL;
264263
const wsScheme = httpURL.startsWith('https') ? 'wss' : 'ws';
265264
MQTT_URL = process.env.MQTT_TEST_URL ?? `${httpURL.replace(/^https?/, wsScheme)}/mqtt`;
266-
267-
const deployBody = await sendOperation(ctx.harper, {
268-
operation: 'deploy_component',
269-
project: PROJECT,
270-
package: FIXTURE_PATH,
271-
restart: true,
272-
});
273-
strictEqual(deployBody.message, `Successfully deployed: ${PROJECT}, restarting Harper`);
274-
275-
// Poll until subscribe to broadcast/# returns a non-143 SUBACK (component registered).
276-
const probe = freshUser('subscriber');
277-
const probeToken = mintRS256Jwt(probe);
278-
const deadline = Date.now() + 30_000;
279-
let ready = false;
280-
let lastError: unknown = null;
281-
let lastCode: number | undefined;
282-
let attempts = 0;
283-
while (Date.now() < deadline) {
284-
attempts++;
285-
let client: MqttClient | undefined;
286-
try {
287-
client = await connect(MQTT_URL, jwtOpts(probeToken, probe));
288-
const granted = await subscribe(client, 'broadcast/#');
289-
lastCode = grantedCodes(granted)[0];
290-
// 143 = no resource registered yet; anything else means component is up.
291-
if (lastCode !== 143) {
292-
ready = true;
293-
break;
294-
}
295-
} catch (err) {
296-
lastError = err;
297-
} finally {
298-
await endQuiet(client);
299-
}
300-
await sleep(500);
301-
}
302-
if (!ready) {
303-
const err = lastError as any;
304-
throw new Error(
305-
`Timed out waiting for mqtt-user-sub after ${attempts} attempts. ` +
306-
`Last SUBACK code: ${lastCode ?? 'n/a'}. Last error: ${err?.message ?? err}`
307-
);
308-
}
309265
});
310266

311267
after(async () => {

0 commit comments

Comments
 (0)