Skip to content

Commit 5c4b93b

Browse files
xuyushun441-sysos-zhuangclaude
authored
test(service-cluster-redis): de-flake Redis wiring test (hoist cold imports) (#1495)
The "Redis driver — wiring" tests did `await import('./index.js')` + `await import('@objectstack/service-cluster')` inside the test body, under the default 5000ms timeout. On a cold/slow CI runner the one-time module load exceeded 5s and the first test failed with "Test timed out in 5000ms" (the second only passed because the first warmed the module cache) — an intermittent red on Test Core unrelated to any product change. Hoist both to top-level static imports: `import './index.js'` still registers the 'redis' driver as a side-effect at module eval, and `defineCluster` is a normal named export. The import cost now lands once at file load, outside any per-test timeout. Test assertions are unchanged. Co-authored-by: Jack Zhuang <277994282+os-zhuang@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 6bc3b18 commit 5c4b93b

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
---
3+
4+
Test-only: stabilize the Redis driver wiring contract test (hoist imports out of the timed test body to fix a flaky 5s timeout on slow CI).

‎packages/services/service-cluster-redis/src/redis.contract.test.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ import {
1717
runKVContract,
1818
runCounterContract,
1919
} from '@objectstack/service-cluster/testing';
20+
// Load the driver entrypoint at module eval — importing it registers the
21+
// 'redis' cluster driver as a side-effect, which `defineCluster({ driver:
22+
// 'redis' })` then resolves. Doing this here (not via `await import()` inside
23+
// the timed test bodies) keeps the one-time cold module-load cost out of the
24+
// per-test 5s timeout — the wiring tests below were flaky on slow CI for
25+
// exactly that reason (the first test paid the full import cost and timed out).
26+
import './index.js';
27+
import { defineCluster } from '@objectstack/service-cluster';
2028

2129
import { RedisPubSub } from './pubsub.js';
2230
import { RedisLock } from './lock.js';
@@ -118,8 +126,6 @@ describe('IPubSub contract — redis(mock)', () => {
118126

119127
describe('Redis driver — wiring', () => {
120128
it('exports a registerable driver and defineCluster picks it up', async () => {
121-
await import('./index.js');
122-
const { defineCluster } = await import('@objectstack/service-cluster');
123129
const client = makeClient();
124130
const cluster = defineCluster({
125131
driver: 'redis',
@@ -145,8 +151,6 @@ describe('Redis driver — wiring', () => {
145151
});
146152

147153
it('does NOT quit caller-owned client on close', async () => {
148-
await import('./index.js');
149-
const { defineCluster } = await import('@objectstack/service-cluster');
150154
const client = makeClient();
151155
const cluster = defineCluster({
152156
driver: 'redis',

0 commit comments

Comments
 (0)