Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#7,204 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
csharp
Ambito
testing

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
C#
Stelle
4k
Fork
139
Merge medio
7h 44m
PR unite (30g)
271

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di thomhurst/TUnit

Tutte le issue di thomhurst/TUnit

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.