Skip to content

test(player,service,library,download): 修复 5 处主分支 -race 并发与时序测试缺陷 #208

Done

Description

@chialecode

现象

在 Ubuntu CI repository-quality 开启 go test -race -count=1 -timeout 15m ./... 后,暴露出 5 处已存在于 main(f61d6866)的仅限测试的并发/时序缺陷:

  1. internal/player/live_preview_test.go 假时钟 NowFunc 数据竞争(PR fix(site): unify Chrome 144 headers, HTTP/2, cookie hygiene, t.co meta-refresh, and Douyin webid persistence #197 run 46246425655):
    • TestOpenLivePreviewGrowingHLSAndFLVFMP4AndDanmakuSuppressed(L242-243, 280, 306, 335)与 TestEndToEndLiveRecorderAndPlayerPreviewFinalizeWithoutHandleConflict(L658-659, 670):测试主协程改写 now 与 Controller.runVideoWorker 后台调用 NullAudioSink.NowFunc() 发生数据竞争;internal/player/player_test.go(L273-275, 305, 319, 352)一并审计统一同步。
  2. internal/service/preview_media_test.go:181 通道丢唤醒超时(PR feat(run): 支持 Windows 开机自动启动(最小化到托盘)及离线空档开播提示 (#136) #194 run 46246187044):
    • TestStagePreviewMediaStreamingLimitCancelAndVideoFriendlyErrors:无缓冲 chunkSent := make(chan struct{}) 配非阻塞 select { case chunkSent <- struct{}{}: default: },处理协程先到时信号丢失导致 5 秒超时。
  3. internal/library/batch_storage_test.go:368 -race 下 2s 耗时预算误报(PR feat(run): 支持 Windows 开机自动启动(最小化到托盘)及离线空档开播提示 (#136) #194 run 46246187044 attempt 2 2.077s、PR test(player,service,library,download): eliminate 5 pre-existing main -race and test ordering flakes #209 run 46248609653 2.130s):
  4. internal/download/weibo_download_test.go:1549 waitForTaskTerminal 早于 activeRun/activeProbeSite 清理返回(PR test(player,service,library,download): eliminate 5 pre-existing main -race and test ordering flakes #209 run 46248609653):
    • TestManualTasksDuringBackoffRespectSingleProbeCapAndNotifyFailure:waitForTaskTerminal 仅轮询数据库终态,未等工作协程清理 mgr.activeRun[taskID] 与 mgr.activeProbeSite[sid],导致紧随其后的 RetryActionable 误判站点仍有在途探测而跳过标记(ran 0 probes, want strictly 1)。
  5. internal/service/event_coalescing_and_lock_safety_test.go 早于 publishBackfillBatchLibraryChanged 结束轮询(PR test(player,service,library,download): eliminate 5 pre-existing main -race and test ordering flakes #209 run 46248609653):
    • TestWeiboBackfillTierABatchCoalescesLibraryEvents(两个子测试):仅等待队列内存状态变为 CacheQueueCompleted,但 backfill.go:868-871 在解锁后才顺序调用 publishBackfillBatchLibraryChanged 和 notifyState(发布 EventCacheQueueUpdated 终态),在慢速 -race 节点上先读到空 libEvents。

修复方案

仅修改测试代码(零生产代码变更,不弱化任何非 -race 断言):

  • internal/player/{player_test,live_preview_test}.go:新增 syncTestClock(sync.Mutex 保护,保留 time.Time 单调时钟与时区),替换全部 3 处 NowFunc 闭包。
  • internal/service/preview_media_test.go:chunkSent := make(chan struct{}, 1)。
  • internal/library/{race_disabled_test,race_enabled_test,batch_storage_test}.go:沿用 PR ci: enable go test -race detector in GitHub Actions Ubuntu CI (DEC-097) #203 规范,!race 保持严格 2s 预算,race 放宽至 10s。
  • internal/download/weibo_download_test.go:waitForTaskTerminal 在确认数据库终态的同时确认 mgr.activeRun[taskID] 已清理。
  • internal/service/event_coalescing_and_lock_safety_test.go:两个子测试同时等待 EventCacheQueueUpdated 完成通知(严格发生在 publishBackfillBatchLibraryChanged 之后),不加任意休眠且完全保留 len(got) == 1 严格断言。

Activity

  1. added
    bug
    in-progress
    on Nov 29, 2026
  2. changed the title [-]test(player): 修复 live_preview_test 假时钟 NowFunc 在 -race 下的数据竞争[/-] [+]test(player,service): 修复 live_preview_test 假时钟 -race 竞争与 preview_media_test 通道丢唤醒[/+] on Nov 29, 2026
  3. changed the title [-]test(player,service): 修复 live_preview_test 假时钟 -race 竞争与 preview_media_test 通道丢唤醒[/-] [+]test(player,service,library,download): 修复 5 处主分支 -race 并发与时序测试缺陷[/+] on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugin-progress

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions