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
Original file line number Diff line number Diff line change
Expand Up @@ -524,13 +524,14 @@ private SynchronizedStringBuilder GetTestContextMessagesStringBuilder()
/// <returns>A fresh context suitable for one folded data-driven iteration.</returns>
internal TestContextImplementation CloneForDataDrivenIteration()
{
// Pass testMethod: null and testClassFullName: null because the relevant labels
// (including TestNameLabel / FullyQualifiedTestClassNameLabel and anything merged from
// AssemblyInitialize / ClassInitialize) are already in _properties. In that branch the
// constructor takes a shallow copy of the passed dictionary, so passing _properties
// directly gives the clone an isolated property bag without an extra intermediate copy:
// per-iteration mutations to the clone's property bag won't leak back to this instance
// nor to subsequent iterations.
// Pass _properties directly and testMethod: null / testClassFullName: null because the
// relevant labels (including TestNameLabel / FullyQualifiedTestClassNameLabel and anything
// merged from AssemblyInitialize / ClassInitialize) are already in the property bag. The
// constructor's null/null branch copies the supplied properties into a fresh dictionary
// via the [with(properties)] spread, so no intermediate snapshot allocation is needed and
// isolation is preserved: per-iteration mutations to the clone's property bag won't leak
// back to this instance nor to subsequent iterations, and mutations to this instance after
// clone creation won't leak into the clone.
var clone = new TestContextImplementation(testMethod: null, testClassFullName: null, _properties, _messageLogger, _testRunCancellationToken);

// Preserve TestRunCount so user code that observes it (e.g. retry-aware tests) sees
Expand Down