test: flaky integration tests when GetRandomMovie() returns a soft-deleted movie
還沒有人認領這個 Issue。
評估
研究方向
從兩個指定的 ServiceApplicationFactory.cs 檔案中的 GetRandomMovie() 開始,比較它們各自如何選取有效電影。在兩種實作中都排除軟刪除的項目,然後執行受影響的用戶端和伺服器整合測試;當隨機選取無法傳回軟刪除的電影且這些測試通過時,即表示完成。
由索引模型根據 Issue 內容生成。
描述
Describe the bug
Several integration tests are intermittently flaky because GetRandomMovie() can return a movie that an earlier test in the same class has already soft-deleted and never restored.
Observed failure, from PR #599 (Build and Test Library, run 42093778343). The change in that PR is unrelated, and the identical commit passed on a fork run:
CommunityToolkit.Datasync.Client.Test.Service.Integration_Tests.Read_SoftDeleted_NotDeleted_Returns200 [FAIL]
CommunityToolkit.Datasync.Client.DatasyncHttpException : Gone
at ServiceResponse.ThrowIfNotSuccessful(...)
at DatasyncServiceClient`1.GetAsync(String id, ...)
at Integration_Tests.Read_SoftDeleted_NotDeleted_Returns200() line 152
Root cause
- Each test class that uses the in-memory test server creates one
ServiceApplicationFactoryviaIClassFixture<ServiceApplicationFactory>. All tests in the class share one in-memory movie repository. GetRandomMovie()picks a random movie that satisfiesIsValid(...)(title, year and duration). It does not exclude movies whereDeleted == true.- Several tests soft-delete a random movie, either with
SoftDelete(existingMovie)or throughDELETE api/in-memory/softmovies/{id}. They never restore it. - If a later test in the same class randomly picks one of those movies and calls the
softmoviesendpoint, the server correctly returns410 Gone(or the test's other expectations break), and the test fails.
The failure rate is low and depends on test ordering. A few leaked soft-deleted rows sit in the set of seeded valid movies, so it is probably in the low single-digit percent range per run. That is why it only appears occasionally in CI.
I could not reproduce it locally. 15 consecutive runs of Service.Integration_Tests all passed.
Affected tests
Any test that calls GetRandomMovie() and expects a non-deleted movie, in a class that also soft-deletes movies. The soft-deleting tests also mutate Deleted state themselves.
tests/CommunityToolkit.Datasync.Client.Test
Service/Integration_Tests.cssoft-deletes inCreate_SoftDeleted_Returns409,Read_SoftDeleted_Deleted_Returns404,Read_SoftDeleted_Deleted_WithIncludeDeleted_Returns200,Delete_NotSoftDeleted_Returns204andDelete_SoftDeletedId_Returns410. All 16GetRandomMovie()call sites in that file are exposed.
tests/CommunityToolkit.Datasync.Server.Test has the same GetRandomMovie() implementation in Helpers/ServiceApplicationFactory.cs, and the same soft-delete pattern:
Service/Read_Tests.cs:Read_SoftDeleted_Deleted_Returns410andRead_SoftDeleted_Deleted_WithIncludeDeleted_Returns200.Read_SoftDeleted_NotDeleted_Returns200has the same signature as the observed failure.Service/Delete_Tests.cs:Delete_NotSoftDeleted_Returns204andDelete_SoftDeletedId_Returns410.Service/Replace_Tests.cs: three soft-delete tests.Service/Create_Tests.cs: one soft-delete test.
Suggested fix
Smallest fix: exclude soft-deleted movies in both GetRandomMovie() implementations:
repository.GetEntities().Where(x => IsValid(x) && !x.Deleted).ToList();
tests/CommunityToolkit.Datasync.Client.Test/Helpers/ServiceApplicationFactory.cstests/CommunityToolkit.Datasync.Server.Test/Helpers/ServiceApplicationFactory.cs
Tests that need a deleted movie already call SoftDelete(...) explicitly, so they are unaffected.
A more robust option is to also restore or reset the repository per test, as ResetInMemoryMovies() already does for the offline push tests. That removes the cross-test state sharing entirely, at some cost in test runtime.
Additional context
Delete_* tests that hard-delete a movie remove it from the repository, so they don't cause this problem. Only soft-deleted rows that stay in the repository do.
- 主要語言
- C#
- 星號
- 184
- 分支
- 48
- 平均合併
- 21 分鐘
- 30 天內合併 PR
- 7
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
CommunityToolkit/Datasync 的其他 Issue
-
Blocked dependencies Server
難度 4/5 3-5 天 新手友好度 25/100
CommunityToolkit/Datasync#594 ·
-
dependencies Examples
難度 4/5 3-5 天 新手友好度 40/100
CommunityToolkit/Datasync#593 ·
-
dependencies Infrastructure
難度 3/5 1-2 天 新手友好度 72/100
CommunityToolkit/Datasync#592 ·
-
dependencies Infrastructure
難度 4/5 3-5 天 新手友好度 48/100
CommunityToolkit/Datasync#591 ·
-
dependencies Infrastructure
難度 2/5 1-3 小時 新手友好度 55/100
CommunityToolkit/Datasync#590 ·
查看 CommunityToolkit/Datasync 的全部 Issue
相似的 Issue
-
enhancement needs-triage
難度 2/5 1-3 小時 新手友好度 78/100
microsoft/microsoft-ui-reactor#1460 ·
維護者通常 1 天內回覆
-
t/bug
難度 2/5 1-3 小時 新手友好度 75/100
dotnet/maui#39950 · 1 個 reaction ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
NimblePros/deviq-hugo#121 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
philterd/phileas-dotnet#188 ·
-
enhancement triaged
難度 2/5 1-3 小時 新手友好度 68/100
nikneem/sessionize-api-client#55 · 3 則留言 ·