Skip to content

Commit b1c0144

Browse files
committed
[Debugger] Deflake instanceof assembly lookup tests
1 parent 8f5b860 commit b1c0144

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

tracer/test/Datadog.Trace.Tests/Debugger/DebuggerExpressionLanguageTests.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,24 +1475,29 @@ public void ProbeExpressionParser_InstanceOf_LazyLoadedType_CanSucceedWithoutRec
14751475
var secondAssembly = CreateDynamicAssembly(
14761476
"InstanceOfLazyAssembly",
14771477
"LazyLoaded.TypeForInstanceOf");
1478+
var includeSecondAssembly = false;
14781479
var calls = 0;
14791480

14801481
try
14811482
{
1483+
// Gate the second assembly on an explicit flag rather than the call count: an unrelated
1484+
// assembly load can bump the generation and make ResolveType retry, so the provider may be
1485+
// invoked more than once per lookup.
14821486
InstanceOfHelper.SetAssemblyProviderForTests(() =>
14831487
{
14841488
calls++;
1485-
return calls == 1 ? [firstAssembly] : [firstAssembly, secondAssembly];
1489+
return includeSecondAssembly ? [firstAssembly, secondAssembly] : [firstAssembly];
14861490
});
14871491

14881492
var instance = Activator.CreateInstance(secondAssembly.GetType("LazyLoaded.TypeForInstanceOf"));
14891493

14901494
Action firstLookup = () => InstanceOfHelper.ResolveType("LazyLoaded.TypeForInstanceOf");
14911495
firstLookup.Should().Throw<Exception>().WithMessage("*unknown type*");
14921496

1497+
includeSecondAssembly = true;
14931498
InstanceOfHelper.IncrementAssemblyLoadGenerationForTests();
14941499
InstanceOfHelper.IsInstanceOf(instance, "LazyLoaded.TypeForInstanceOf").Should().BeTrue();
1495-
calls.Should().Be(2);
1500+
calls.Should().BeGreaterThan(1);
14961501
}
14971502
finally
14981503
{
@@ -1570,24 +1575,29 @@ public void ProbeExpressionParser_InstanceOf_MissScansOnlyNewAssemblies()
15701575
{
15711576
var firstAssembly = typeof(string).Assembly;
15721577
var secondAssembly = typeof(TestStruct.NestedObject).Assembly;
1578+
var includeSecondAssembly = false;
15731579
var calls = 0;
15741580

15751581
try
15761582
{
1583+
// Gate the second assembly on an explicit flag rather than the call count: an unrelated
1584+
// assembly load can bump the generation and make ResolveType retry, so the provider may be
1585+
// invoked more than once per lookup.
15771586
InstanceOfHelper.SetAssemblyProviderForTests(() =>
15781587
{
15791588
calls++;
1580-
return calls == 1 ? [firstAssembly] : [firstAssembly, secondAssembly];
1589+
return includeSecondAssembly ? [firstAssembly, secondAssembly] : [firstAssembly];
15811590
});
15821591

15831592
Action firstLookup = () => InstanceOfHelper.ResolveType("Missing.TypeForInstanceOf");
15841593
firstLookup.Should().Throw<Exception>().WithMessage("*unknown type*");
15851594

1595+
includeSecondAssembly = true;
15861596
InstanceOfHelper.IncrementAssemblyLoadGenerationForTests();
15871597
Action secondLookup = () => InstanceOfHelper.ResolveType("Missing.TypeForInstanceOf");
15881598
secondLookup.Should().Throw<Exception>().WithMessage("*unknown type*");
15891599

1590-
calls.Should().Be(2);
1600+
calls.Should().BeGreaterThan(1);
15911601
}
15921602
finally
15931603
{
@@ -1609,23 +1619,28 @@ public void ProbeExpressionParser_InstanceOf_LargeMissCacheScansOnlyNewAssemblie
16091619
var resolvedAssembly = CreateDynamicAssembly(
16101620
"InstanceOfLargeMissCacheResolvedAssembly",
16111621
"LargeMissCache.ResolvedType");
1622+
var includeResolvedAssembly = false;
16121623
var calls = 0;
16131624

16141625
try
16151626
{
1627+
// Gate the resolved assembly on an explicit flag rather than the call count: an unrelated
1628+
// assembly load can bump the generation and make ResolveType retry, so the provider may be
1629+
// invoked more than once per lookup.
16161630
InstanceOfHelper.SetAssemblyProviderForTests(() =>
16171631
{
16181632
calls++;
1619-
return calls == 1 ? initialAssemblies : [.. initialAssemblies, resolvedAssembly];
1633+
return includeResolvedAssembly ? [.. initialAssemblies, resolvedAssembly] : initialAssemblies;
16201634
});
16211635

16221636
Action firstLookup = () => InstanceOfHelper.ResolveType("LargeMissCache.ResolvedType");
16231637
firstLookup.Should().Throw<Exception>().WithMessage("*unknown type*");
16241638

1639+
includeResolvedAssembly = true;
16251640
InstanceOfHelper.IncrementAssemblyLoadGenerationForTests();
16261641
InstanceOfHelper.ResolveType("LargeMissCache.ResolvedType").Should().Be(resolvedAssembly.GetType("LargeMissCache.ResolvedType"));
16271642

1628-
calls.Should().Be(2);
1643+
calls.Should().BeGreaterThan(1);
16291644
}
16301645
finally
16311646
{

0 commit comments

Comments
 (0)