Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions TUnit.Engine/Services/ObjectLifecycleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ private async Task InitializeTrackedObjectsAsync(TestContext testContext, Cancel
var tasks = new List<Task>(objectsAtLevel.Count);
foreach (var obj in objectsAtLevel)
{
tasks.Add(InitializeObjectWithSpanAsync(obj, testContext, cancellationToken));
// Tracked objects were discovered before execution and are already
// ordered deepest-first, so nested graph traversal would be redundant.
tasks.Add(InitializeObjectWithSpanAsync(obj, testContext, cancellationToken, includeNestedObjects: false));
}

if (tasks.Count > 0)
Expand All @@ -268,11 +270,18 @@ private async Task InitializeTrackedObjectsAsync(TestContext testContext, Cancel

/// <summary>
/// Initializes an object and its nested objects, wrapped in a scope-aware OpenTelemetry span.
/// Used for objects outside the tracked graph, such as the test class instance.
/// </summary>
private async Task InitializeObjectWithSpanAsync(object obj, TestContext testContext, CancellationToken cancellationToken)
private async Task InitializeObjectWithSpanAsync(
object obj,
TestContext testContext,
CancellationToken cancellationToken,
bool includeNestedObjects = true)
{
// First initialize nested objects depth-first
await InitializeNestedObjectsForExecutionAsync(obj, cancellationToken);
if (includeNestedObjects)
{
await InitializeNestedObjectsForExecutionAsync(obj, cancellationToken);
}

#if NET
var sharedType = TraceScopeRegistry.GetSharedType(obj);
Expand All @@ -299,6 +308,7 @@ private async Task InitializeObjectWithSpanAsync(object obj, TestContext testCon
await ObjectInitializer.InitializeAsync(obj, cancellationToken);
}
#else
_ = testContext;
await ObjectInitializer.InitializeAsync(obj, cancellationToken);
#endif
}
Expand Down
Loading