Skip to content
Open
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: 16 additions & 2 deletions test/OpenTelemetry.OpAmp.Client.Tests/WsTransportTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,14 @@ public async Task WsTransport_DropsOversizedResponseWithoutDispatchingFrame()

using var wsTransport = CreateTransport(opAmpServer.Endpoint, frameProcessor);
await wsTransport.StartAsync(CancellationToken.None);
await wsTransport.SendAsync(FrameGenerator.GenerateMockAgentFrame().Frame, CancellationToken.None);

// SendAsync can race with the receiver aborting the socket after detecting the oversized response.
// On .NET Framework this may surface as a WebSocketException (Aborted state) or OperationCanceledException.
var sendException = await Record.ExceptionAsync(
() => wsTransport.SendAsync(FrameGenerator.GenerateMockAgentFrame().Frame, CancellationToken.None));
Assert.True(
sendException is null || sendException is WebSocketException || sendException is OperationCanceledException,
$"Unexpected exception from SendAsync: {sendException}");

Assert.True(opAmpServer.TryGetClientCloseStatus(TimeSpan.FromSeconds(5), out var closeStatus));
Assert.Equal(WebSocketCloseStatus.MessageTooBig, closeStatus);
Expand Down Expand Up @@ -313,7 +320,14 @@ public async Task WsTransport_LogsOversizedResponseWarning()

using var wsTransport = CreateTransport(opAmpServer.Endpoint, new FrameProcessor());
await wsTransport.StartAsync(CancellationToken.None);
await wsTransport.SendAsync(FrameGenerator.GenerateMockAgentFrame().Frame, CancellationToken.None);

// SendAsync can race with the receiver aborting the socket after detecting the oversized response.
// On .NET Framework this may surface as a WebSocketException (Aborted state) or OperationCanceledException.
var sendException = await Record.ExceptionAsync(
() => wsTransport.SendAsync(FrameGenerator.GenerateMockAgentFrame().Frame, CancellationToken.None));
Assert.True(
sendException is null || sendException is WebSocketException || sendException is OperationCanceledException,
$"Unexpected exception from SendAsync: {sendException}");

Assert.True(opAmpServer.TryGetClientCloseStatus(TimeSpan.FromSeconds(5), out var closeStatus));
Assert.Equal(WebSocketCloseStatus.MessageTooBig, closeStatus);
Expand Down
Loading