Skip to content

Commit aa70ad6

Browse files
authored
run Http3_WaitForConnection_RecordedWhenWaitingForStream with RemoteExecutor (#116741)
#114083 incorrectly added a test that uses `ActivityRecorder` without process isolation via `RemoteExecutor`. This may lead to the registered `ActivityListener` callbacks firing from unrelated tests running in parallel. I started seeing frequent local failures because of this, the stack trace in #116279 (comment) also seems to be related.
1 parent 4aa5460 commit aa70ad6

File tree

2 files changed

+54
-50
lines changed

2 files changed

+54
-50
lines changed

src/libraries/System.Net.Http/tests/FunctionalTests/DiagnosticsTests.cs

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,75 +1591,79 @@ await GetFactoryForVersion(UseVersion).CreateServerAsync(async (server, uri) =>
15911591
});
15921592
}
15931593

1594-
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))]
1594+
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
15951595
public async Task Http3_WaitForConnection_RecordedWhenWaitingForStream()
15961596
{
15971597
if (UseVersion != HttpVersion30 || !TestAsync)
15981598
{
15991599
throw new SkipTestException("This test is specific to async HTTP/3 runs.");
16001600
}
16011601

1602-
using Http3LoopbackServer server = CreateHttp3LoopbackServer(new Http3Options() { MaxInboundBidirectionalStreams = 1 });
1602+
await RemoteExecutor.Invoke(RunTest).DisposeAsync();
1603+
static async Task RunTest()
1604+
{
1605+
using Http3LoopbackServer server = CreateHttp3LoopbackServer(new Http3Options() { MaxInboundBidirectionalStreams = 1 });
16031606

1604-
TaskCompletionSource stream1Created = new();
1605-
TaskCompletionSource allRequestsWaiting = new();
1607+
TaskCompletionSource stream1Created = new();
1608+
TaskCompletionSource allRequestsWaiting = new();
16061609

1607-
Task serverTask = Task.Run(async () =>
1608-
{
1609-
await using Http3LoopbackConnection connection = (Http3LoopbackConnection)await server.EstablishGenericConnectionAsync();
1610-
Http3LoopbackStream stream1 = await connection.AcceptRequestStreamAsync();
1611-
stream1Created.SetResult();
1610+
Task serverTask = Task.Run(async () =>
1611+
{
1612+
await using Http3LoopbackConnection connection = (Http3LoopbackConnection)await server.EstablishGenericConnectionAsync();
1613+
Http3LoopbackStream stream1 = await connection.AcceptRequestStreamAsync();
1614+
stream1Created.SetResult();
16121615

1613-
await allRequestsWaiting.Task;
1614-
await stream1.HandleRequestAsync();
1615-
await stream1.DisposeAsync();
1616+
await allRequestsWaiting.Task;
1617+
await stream1.HandleRequestAsync();
1618+
await stream1.DisposeAsync();
16161619

1617-
Http3LoopbackStream stream2 = await connection.AcceptRequestStreamAsync();
1618-
await stream2.HandleRequestAsync();
1619-
await stream2.DisposeAsync();
1620+
Http3LoopbackStream stream2 = await connection.AcceptRequestStreamAsync();
1621+
await stream2.HandleRequestAsync();
1622+
await stream2.DisposeAsync();
16201623

1621-
Http3LoopbackStream stream3 = await connection.AcceptRequestStreamAsync();
1622-
await stream3.HandleRequestAsync();
1623-
await stream3.DisposeAsync();
1624-
});
1624+
Http3LoopbackStream stream3 = await connection.AcceptRequestStreamAsync();
1625+
await stream3.HandleRequestAsync();
1626+
await stream3.DisposeAsync();
1627+
});
16251628

1626-
Task clientTask = Task.Run(async () =>
1627-
{
1628-
using Activity parentActivity = new Activity("parent").Start();
1629-
using ActivityRecorder requestRecorder = new("System.Net.Http", "System.Net.Http.HttpRequestOut")
1630-
{
1631-
ExpectedParent = parentActivity
1632-
};
1633-
using ActivityRecorder waitForConnectionRecorder = new("Experimental.System.Net.Http.Connections", "Experimental.System.Net.Http.Connections.WaitForConnection")
1634-
{
1635-
VerifyParent = false
1636-
};
1637-
waitForConnectionRecorder.OnStarted = a =>
1629+
Task clientTask = Task.Run(async () =>
16381630
{
1639-
if (waitForConnectionRecorder.Started == 3)
1631+
using Activity parentActivity = new Activity("parent").Start();
1632+
using ActivityRecorder requestRecorder = new("System.Net.Http", "System.Net.Http.HttpRequestOut")
16401633
{
1641-
allRequestsWaiting.SetResult();
1642-
}
1643-
};
1634+
ExpectedParent = parentActivity
1635+
};
1636+
using ActivityRecorder waitForConnectionRecorder = new("Experimental.System.Net.Http.Connections", "Experimental.System.Net.Http.Connections.WaitForConnection")
1637+
{
1638+
VerifyParent = false
1639+
};
1640+
waitForConnectionRecorder.OnStarted = a =>
1641+
{
1642+
if (waitForConnectionRecorder.Started == 3)
1643+
{
1644+
allRequestsWaiting.SetResult();
1645+
}
1646+
};
16441647

1645-
SocketsHttpHandler handler = CreateSocketsHttpHandler(allowAllCertificates: true);
1646-
using HttpClient client = new HttpClient(CreateSocketsHttpHandler(allowAllCertificates: true))
1647-
{
1648-
DefaultRequestVersion = HttpVersion30,
1649-
DefaultVersionPolicy = HttpVersionPolicy.RequestVersionExact
1650-
};
1648+
SocketsHttpHandler handler = CreateSocketsHttpHandler(allowAllCertificates: true);
1649+
using HttpClient client = new HttpClient(CreateSocketsHttpHandler(allowAllCertificates: true))
1650+
{
1651+
DefaultRequestVersion = HttpVersion30,
1652+
DefaultVersionPolicy = HttpVersionPolicy.RequestVersionExact
1653+
};
16511654

1652-
Task<HttpResponseMessage> request1Task = client.GetAsync(server.Address);
1653-
await stream1Created.Task;
1655+
Task<HttpResponseMessage> request1Task = client.GetAsync(server.Address);
1656+
await stream1Created.Task;
16541657

1655-
Task<HttpResponseMessage> request2Task = client.GetAsync(server.Address);
1656-
Task<HttpResponseMessage> request3Task = client.GetAsync(server.Address);
1658+
Task<HttpResponseMessage> request2Task = client.GetAsync(server.Address);
1659+
Task<HttpResponseMessage> request3Task = client.GetAsync(server.Address);
16571660

1658-
await new Task[] { request1Task, request2Task, request3Task }.WhenAllOrAnyFailed(30_000);
1659-
Assert.Equal(3, waitForConnectionRecorder.Stopped);
1660-
});
1661+
await new Task[] { request1Task, request2Task, request3Task }.WhenAllOrAnyFailed(30_000);
1662+
Assert.Equal(3, waitForConnectionRecorder.Stopped);
1663+
});
16611664

1662-
await new Task[] { serverTask, clientTask }.WhenAllOrAnyFailed(30_000);
1665+
await new Task[] { serverTask, clientTask }.WhenAllOrAnyFailed(30_000);
1666+
}
16631667
}
16641668

16651669
private static T GetProperty<T>(object obj, string propertyName)

src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.SocketsHttpHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected static HttpClientHandler CreateHttpClientHandler(Version useVersion =
6363
protected static SocketsHttpHandler CreateSocketsHttpHandler(bool allowAllCertificates)
6464
=> TestHelper.CreateSocketsHttpHandler(allowAllCertificates);
6565

66-
protected Http3LoopbackServer CreateHttp3LoopbackServer(Http3Options options = default)
66+
protected static Http3LoopbackServer CreateHttp3LoopbackServer(Http3Options options = default)
6767
{
6868
return new Http3LoopbackServer(options);
6969
}

0 commit comments

Comments
 (0)