Repository navigation
fix(tests): record progress events synchronously to remove flake - #2
Merged
Merged
Conversation
Progress<T> posts callbacks to the captured SynchronizationContext, so under xUnit's AsyncTestSyncContext events could arrive after the awaited call returned and the assertions had already run. Use a shared synchronous ListProgress so RunAsyncContinuesAfterSkippedItem and RunAsyncReportsStagesAndOutputPath observe every event deterministically. Co-Authored-By: Claude Code <noreply@anthropic.com>
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.
问题
release 工作流 (run 39021878275) 的
bsp-localization-tools / buildjob 失败:失败时收集到的进度事件停在第二个 BSP 的
ExtractingGameText,缺少Completed。根因
测试用
new Progress<TranslationProgress>(progressEvents.Add)收集进度。Progress<T>.Report不直接调用回调,而是把回调 Post 到捕获的 SynchronizationContext;xUnit 的AsyncTestSyncContext会把它排到线程池。因此await RunAsync(...)返回、断言开始执行时,末尾的事件可能尚未写入列表,断言偶发落空。属于测试竞态,产品代码无问题。同一文件中原有的
RunAsyncReportsNestedItemProgressBeforeReturning已经使用同步的ListProgress,本 PR 将这一做法提取为共享辅助类并用于两个受影响用例。改动
tests/BSPLocalizationTools.Tests/ListProgress.cs:同步IProgress<TranslationProgress>实现BatchLocalizationRunnerTests.RunAsyncContinuesAfterSkippedItem改用ListProgress,移除重复的内嵌实现LocalizationRunnerProgressTests.RunAsyncReportsStagesAndOutputPath改用ListProgress(该用例也有progressEvents[^1].Stage断言,存在同样的竞态)验证
dotnet build:0 警告 0 错误dotnet test -c Release连续运行 10 次:每次85 passed, 0 failed🤖 Generated with Claude Code