Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Shared data-source instances are reused after disposal by tests registered later in the session

Đang mở
#7,204 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
68/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
csharp
Lĩnh vực
testing

Hướng nghiên cứu

Read src/TUnit.Core/Tracking/ObjectTracker.cs around UntrackObject, then inspect the shared-instance lookup methods in src/TUnit.Core/TestDataContainer.cs. Reproduce the issue with a disposable shared data source and a dynamic test registered after its original holder completes; verify the later test receives a new, undisposed instance. The report says the repro has not yet been run.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug

What happens

When the last test holding a shared data-source instance (Shared = SharedType.Keyed, PerClass, PerAssembly or PerTestSession) completes, ObjectTracker.UntrackObject brings its reference count to zero and disposes it. TestDataContainer still caches the instance (ScopedDictionary.GetOrCreate), and it is only cleared by TestDataContainer.Reset() at the end of the session. A test that is registered later in the same session asks the container for the same key or scope, gets the disposed instance back, and gets a fresh reference count of 1 on it.

The usual way to register a test later is a dynamic test added at run time, after the original holders have completed.

Where

  • src/TUnit.Core/Tracking/ObjectTracker.cs, UntrackObject: disposes when the count reaches 0 and removes only the tracker entry.
  • src/TUnit.Core/TestDataContainer.cs, GetInstanceForKey / GetInstanceForClass / GetInstanceForAssembly / GetGlobalInstance: these return the cached instance whether or not it has been disposed.

How to reproduce

  1. Test A: [ClassDataSource<MyDisposable>(Shared = SharedType.Keyed, Key = "k")], where MyDisposable records IsDisposed.
  2. Test B: [DependsOn(nameof(A))] adds a dynamic test at run time whose class or method takes [ClassDataSource<MyDisposable>(Shared = SharedType.Keyed, Key = "k")].
  3. The dynamic test receives the instance that A's completion already disposed (IsDisposed == true).

This applies whatever A's outcome is (passed, failed, or skipped once #7191 merges). I found it by reading the code while reviewing #7191, where Greptile raised it for skipped tests. I have not run the repro yet.

Expected

A test registered after a shared instance has been disposed gets a new instance. For example, the container could drop its cache entry when the tracker disposes the object (ObjectTracker.OnDisposed), or the container could skip disposed entries.

Ngôn ngữ chính
C#
Star
4k
Fork
139
Merge trung bình
7 giờ 44 phút
Pull request đã merge (30 ngày)
271

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của thomhurst/TUnit

Tất cả issue của thomhurst/TUnit

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.