Repository navigation
test(jobs): 用真实 Redis 双实例实测「一次 tick 只执行一次」 - #43
Merged
Merged
Conversation
对标 #12.5 验收门槛里的最后一条:「集群双实例只执行一次」。 在此之前这条只有**推论** —— `bullmq-backend.ts` 的注释写着「BullMQ 保证一个 job 只被一个 worker 取走,`upsertJobScheduler` 每个 id 只有一份调度」。注释不是证据。 新增 `apps/api/tests/integration/jobs-redis-cluster.test.ts`(3 例,真实 Redis): 1. **两个副本声明同一个调度 → Redis 里只有一份**。否则每个副本按自己的节奏各发 一遍任务,用户会收到双份通知。 2. **两个副本同时运行 → 一次 tick 只执行一次**。除了总数上限,还断言任意两次执行 的间隔 > 400ms(间隔 1s 的调度不会出现「几乎同时两次」,那正是双取的特征)。 同时断言执行次数 ≥ 2 —— 防的是「测试因为根本没跑而通过」。 3. **同一个 `jobId` 从两个副本入队 → 只执行一次**。 ## 为什么需要独立 db 用例清理用 `obliterate`,会删掉整个队列。所以: - 只在 `TEST_REDIS_URL` 指向 **db ≥ 1** 时运行(本机验证过 `…/6379` 与 `…/6379/0` 都会被跳过,不会误清开发库); - CI 里加 `TEST_REDIS_URL: redis://127.0.0.1:6379/9`(redis service 本来就在)。 不设环境变量时整组跳过,不给本地开发引入常驻 Redis 依赖。 验证:本机对着 `sp-redis` 跑 3 例全绿(4.9s);不设 / 设 db 0 两种写法均 3 skipped;eslint 干净。
worable233
force-pushed
the
test/jobs-redis-cluster
branch
from
October 25, 2026 10:43
e340de6 to
02ac9b6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
对标 #12.5 验收门槛里的最后一条:「集群双实例只执行一次」。
在此之前这条只有推论 ——
bullmq-backend.ts的注释写着「BullMQ 保证一个 job 只被一个 worker 取走,upsertJobScheduler每个 id 只有一份调度」。注释不是证据。新增 3 例(真实 Redis,两个独立 backend = 两个副本)
jobId从两个副本入队 → 只执行一次为什么需要独立 db
用例清理用
obliterate,会删掉整个队列。所以:TEST_REDIS_URL指向 db ≥ 1 时运行(本机验证过…/6379与…/6379/0都会被跳过,不会误清开发库)TEST_REDIS_URL: redis://127.0.0.1:6379/9(redis service 本来就在)验证
本机对着
sp-redis跑 3 例全绿(4.9s);不设 / 设 db 0 两种写法均 3 skipped;eslint 干净。