Skip to content

Commit 3086e6a

Browse files
committed
test(redis): stabilize fallback hash TTL assertion
1 parent cfac4be commit 3086e6a

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/services/redis-client.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,15 @@ class ObservableDeferredConnectRedisRuntime
272272
}
273273

274274
async function waitFor(
275-
condition: () => boolean,
275+
condition: () => boolean | Promise<boolean>,
276276
timeoutMs = 200,
277277
): Promise<void> {
278278
const deadline = Date.now() + timeoutMs;
279279
while (Date.now() < deadline) {
280-
if (condition()) return;
280+
if (await condition()) return;
281281
await new Promise((resolve) => setTimeout(resolve, 5));
282282
}
283-
assert(condition(), "condition not met before timeout");
283+
assert(await condition(), "condition not met before timeout");
284284
}
285285

286286
describe("redis client", () => {
@@ -458,9 +458,11 @@ describe("redis client", () => {
458458
lastQuery: "Continue overhaul",
459459
});
460460

461-
await new Promise((resolve) => setTimeout(resolve, 10));
462-
463-
assertEquals(await redis.getHashAll("memory-cache:group-1:meta"), {});
461+
await waitFor(async () =>
462+
Object.keys(await redis.getHashAll("memory-cache:group-1:meta"))
463+
.length ===
464+
0
465+
);
464466
await redis.close();
465467
});
466468

0 commit comments

Comments
 (0)