Repository navigation
fix: raise lifecycle delegate events and preserve data-row scope ownership #7417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
1b6c09f
fix: dispatch test context lifecycle delegates (#7308)
thomhurst 2ba3c66
fix: preserve class row callbacks and retry scope lifetime (#7308)
thomhurst daf26b3
fix: preserve row state and isolate class callbacks (#7308)
thomhurst a0e3e58
fix: isolate factory state between data rows (#7308)
thomhurst b5f51b3
fix(core): leave scope-owned arguments to their DI scope (#7308)
thomhurst 0139166
fix: balance scope references and preserve cleanup order (#7308)
thomhurst d8d8af7
fix: dispose DI scopes in dependency graph order (#7308)
thomhurst 993e845
fix: retain DI cleanup for skipped and failed rows (#7308)
thomhurst c9d5e82
fix: preserve row cleanup ownership and retry cancellation (#7308)
thomhurst 02d1090
fix: keep claimed scope cleanup off enumeration failures (#7308)
thomhurst 0c27ce0
fix: guard class iterator failure cleanup ownership (#7308)
thomhurst 4d8ad3d
fix: isolate class source and constructor factory contexts (#7308)
thomhurst 44e3b81
fix: preserve enumeration state across class factories (#7308)
thomhurst d7b2518
fix: retain constructor updates and unclaimed cleanup (#7308)
thomhurst a85e4ba
fix: compare saved class state against immutable baseline (#7308)
thomhurst b2da25e
fix: replay saved constructor state removals (#7308)
thomhurst 45e85ce
fix: preserve method-enumeration state removals (#7308)
thomhurst 95e05fd
fix: complete property data-source lifecycle dispatch (#7308)
thomhurst 5b38538
Merge main and preserve lifecycle scope cleanup across scheduler path…
thomhurst f9136c5
fix: preserve row callbacks and synchronize session cleanup (#7308)
thomhurst 009efea
fix: model data-row scope ownership explicitly (#7308)
thomhurst 0017885
fix: retain lazy constructor event sharing for #7308
thomhurst 08df302
fix: retain rejected row cleanup and encapsulate contexts (#7308)
thomhurst b3435e8
fix: snapshot lifecycle delegate dispatch for #7308
thomhurst 91a17f7
fix: retain rejected method-row cleanup state for #7308
thomhurst 101f074
Merge remote-tracking branch 'origin/main' into issue-7308-events
thomhurst eafd1f3
fix: allow registration-hold cleanup without a test context (#7308)
thomhurst 2f39ed7
fix: refresh constructor state baseline for refetched rows (#7308)
thomhurst a454169
fix: isolate empty constructor state snapshots (#7308)
thomhurst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| namespace TUnit.Core; | ||
|
|
||
| /// <summary> | ||
| /// Owns a row's scopes. Object lookup releases each scope at its first resolved object's graph | ||
| /// depth; completion releases scopes left by failed factories or untracked values. | ||
| /// </summary> | ||
| internal sealed class DataRowScopeCollection | ||
| { | ||
| private readonly List<ScopeOwner> _owners = []; | ||
| private readonly Dictionary<object, List<ScopeOwner>> _objects = new(Helpers.ReferenceEqualityComparer.Instance); | ||
|
|
||
| internal ScopeOwner Register(object? scope) | ||
| { | ||
| var owner = new ScopeOwner(scope); | ||
| _owners.Add(owner); | ||
| return owner; | ||
| } | ||
|
|
||
| internal void RegisterObject(ScopeOwner owner, object? instance) | ||
| { | ||
| if (instance is null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (!_objects.TryGetValue(instance, out var owners)) | ||
| { | ||
| _objects.Add(instance, owners = []); | ||
| } | ||
|
|
||
| if (!owners.Contains(owner)) | ||
| { | ||
| owners.Add(owner); | ||
| } | ||
| } | ||
|
|
||
| internal DataRowScopeCollection Clone() | ||
| { | ||
| var clone = new DataRowScopeCollection(); | ||
| clone.AddRange(this); | ||
| return clone; | ||
| } | ||
|
|
||
| internal void AddRange(DataRowScopeCollection scopes) | ||
| { | ||
| _owners.AddRange(scopes._owners); | ||
| foreach (var pair in scopes._objects) | ||
| { | ||
| foreach (var owner in pair.Value) | ||
| { | ||
| RegisterObject(owner, pair.Key); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| internal ValueTask<List<Exception>?> ReleaseAsync(object instance, List<Exception>? exceptions = null) | ||
| => _objects.TryGetValue(instance, out var owners) | ||
| ? DisposeAsync(owners, exceptions) | ||
| : new(exceptions); | ||
|
|
||
| internal ValueTask<List<Exception>?> CompleteAsync(List<Exception>? exceptions = null) | ||
| => DisposeAsync(_owners, exceptions); | ||
|
|
||
| private static async ValueTask<List<Exception>?> DisposeAsync(List<ScopeOwner> owners, List<Exception>? exceptions) | ||
| { | ||
| foreach (var owner in owners) | ||
| { | ||
| try | ||
| { | ||
| await owner.DisposeAsync().ConfigureAwait(false); | ||
| } | ||
| catch (Exception exception) | ||
| { | ||
| (exceptions ??= []).Add(exception); | ||
| } | ||
| } | ||
|
|
||
| return exceptions; | ||
| } | ||
|
|
||
| /// <summary>Shared by cloned rows; scope disposal is attempted once, including when it throws.</summary> | ||
| internal sealed class ScopeOwner(object? scope) | ||
| { | ||
| private int _disposed; | ||
|
|
||
| internal async ValueTask DisposeAsync() | ||
| { | ||
| if (Interlocked.Exchange(ref _disposed, 1) != 0) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (scope is IAsyncDisposable asyncDisposable) | ||
| { | ||
| await asyncDisposable.DisposeAsync().ConfigureAwait(false); | ||
| } | ||
| else if (scope is IDisposable disposable) | ||
| { | ||
| disposable.Dispose(); | ||
| } | ||
| } | ||
| } | ||
| } |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.