Repository navigation
Done
Labels
Description
现象
在 Ubuntu CI repository-quality 开启 go test -race -count=1 -timeout 15m ./... 后,暴露出 5 处已存在于 main(f61d6866)的仅限测试的并发/时序缺陷:
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 run46246425655):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)一并审计统一同步。
internal/service/preview_media_test.go:181通道丢唤醒超时(PR feat(run): 支持 Windows 开机自动启动(最小化到托盘)及离线空档开播提示 (#136) #194 run46246187044):TestStagePreviewMediaStreamingLimitCancelAndVideoFriendlyErrors:无缓冲chunkSent := make(chan struct{})配非阻塞select { case chunkSent <- struct{}{}: default: },处理协程先到时信号丢失导致 5 秒超时。
internal/library/batch_storage_test.go:368-race下 2s 耗时预算误报(PR feat(run): 支持 Windows 开机自动启动(最小化到托盘)及离线空档开播提示 (#136) #194 run46246187044attempt 22.077s、PR test(player,service,library,download): eliminate 5 pre-existing main -race and test ordering flakes #209 run462486096532.130s):TestStatisticsAuthorItemCountAndBytesWithViaAnd5000Items:纯 Go SQLite 在-race插桩下查询 5,000 条记录约 2.1s,超出硬编码2*time.Second(PR ci: enable go test -race detector in GitHub Actions Ubuntu CI (DEC-097) #203 对internal/ui与移动端library已加//go:build race/!race预算区分,此处遗漏)。
internal/download/weibo_download_test.go:1549waitForTaskTerminal早于activeRun/activeProbeSite清理返回(PR test(player,service,library,download): eliminate 5 pre-existing main -race and test ordering flakes #209 run46248609653):TestManualTasksDuringBackoffRespectSingleProbeCapAndNotifyFailure:waitForTaskTerminal仅轮询数据库终态,未等工作协程清理mgr.activeRun[taskID]与mgr.activeProbeSite[sid],导致紧随其后的RetryActionable误判站点仍有在途探测而跳过标记(ran 0 probes, want strictly 1)。
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 run46248609653):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
[-]test(player): 修复 live_preview_test 假时钟 NowFunc 在 -race 下的数据竞争[/-][+]test(player,service): 修复 live_preview_test 假时钟 -race 竞争与 preview_media_test 通道丢唤醒[/+][-]test(player,service): 修复 live_preview_test 假时钟 -race 竞争与 preview_media_test 通道丢唤醒[/-][+]test(player,service,library,download): 修复 5 处主分支 -race 并发与时序测试缺陷[/+]