test: flaky integration tests when GetRandomMovie() returns a soft-deleted movie
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
Bắt đầu với GetRandomMovie() trong hai tệp ServiceApplicationFactory.cs được nêu và so sánh cách mỗi tệp chọn phim hợp lệ. Loại trừ các mục đã xóa mềm trong cả hai phần triển khai, sau đó chạy các bài kiểm thử tích hợp phía client và server có liên quan; công việc hoàn tất khi việc chọn ngẫu nhiên không thể trả về phim đã xóa mềm và các bài kiểm thử đó đều đạt.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- C#
- Star
- 184
- Fork
- 48
- Merge trung bình
- 21 phút
- Pull request đã merge (30 ngày)
- 7
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của CommunityToolkit/Datasync
-
Blocked dependencies Server
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
CommunityToolkit/Datasync#594 ·
-
dependencies Examples
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 40/100
CommunityToolkit/Datasync#593 ·
-
dependencies Infrastructure
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
CommunityToolkit/Datasync#592 ·
-
dependencies Infrastructure
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
CommunityToolkit/Datasync#591 ·
-
dependencies Infrastructure
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 55/100
CommunityToolkit/Datasync#590 ·
Tất cả issue của CommunityToolkit/Datasync
Issue tương tự
-
Bug: Needs Replicating
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
space-wizards/RobustToolbox#7189 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
microsoft/microsoft-ui-reactor#1460 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
t/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
dotnet/maui#39950 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
The server's default HttpClient fails on plain http and on HTTPS servers without HTTP/2Có thể đã có người làm @yasmoradi đã nhận hôm nay. Đang mởarea / templates
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
bitfoundation/bitplatform#14659 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
DbTransaction.SupportsSavepoints docs say Release/ReleaseAsync are expected to throw, but they are no-ops by designCó thể đã có người làm @alaricd đã nhận hôm nay. Đang mởarea-System.Transactions untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
dotnet/runtime#137040 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày