Skip to content
Merged
Show file tree
Hide file tree
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: 15 additions & 3 deletions test/LaunchDarkly.EventSource.Tests/EventSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,25 @@
return ret;
}

public void ExpectActions(params Action[] expectedActions)
public void ExpectActions(params Action[] expectedActions) =>
ExpectActions(null, expectedActions);

public void ExpectActions(Func<Action, bool> allowSkip, params Action[] expectedActions)
{
int i = 0;
foreach (var a in expectedActions)
{
Assert.True(_actions.TryTake(out var actual, WaitForActionTimeout),
"timed out waiting for action " + i + " (" + a + ")");
Action actual;
while (true)
{
Assert.True(_actions.TryTake(out actual, WaitForActionTimeout),
"timed out waiting for action " + i + " (" + a + ")");
if (allowSkip != null && allowSkip(actual))
{
continue;
}
break;
}

// The MessageEvent.Equals method takes Origin into account, which is inconvenient for
// our tests because the origin will vary for each embedded test server. So, ignore it.
Expand All @@ -127,13 +139,13 @@

if (!actual.Equals(expected))
{
Assert.True(false, "action " + i + " should have been " + expected + ", was " + actual);

Check warning on line 142 in test/LaunchDarkly.EventSource.Tests/EventSink.cs

View workflow job for this annotation

GitHub Actions / build-and-run (windows-latest)

Do not use Assert.True(false, message) to fail a test. Use Assert.Fail(message) instead. (https://xunit.net/xunit.analyzers/rules/xUnit2020)

Check warning on line 142 in test/LaunchDarkly.EventSource.Tests/EventSink.cs

View workflow job for this annotation

GitHub Actions / build-and-run (ubuntu-latest)

Do not use Assert.True(false, message) to fail a test. Use Assert.Fail(message) instead. (https://xunit.net/xunit.analyzers/rules/xUnit2020)
}
if (actual.Kind == "MessageReceived" && ExpectUtf8Data.HasValue)
{
if (actual.Message.IsDataUtf8Bytes != ExpectUtf8Data.Value)
{
Assert.True(false, "action " + i + "(" + actual + ") - data should have been read as "

Check warning on line 148 in test/LaunchDarkly.EventSource.Tests/EventSink.cs

View workflow job for this annotation

GitHub Actions / build-and-run (windows-latest)

Do not use Assert.True(false, message) to fail a test. Use Assert.Fail(message) instead. (https://xunit.net/xunit.analyzers/rules/xUnit2020)

Check warning on line 148 in test/LaunchDarkly.EventSource.Tests/EventSink.cs

View workflow job for this annotation

GitHub Actions / build-and-run (ubuntu-latest)

Do not use Assert.True(false, message) to fail a test. Use Assert.Fail(message) instead. (https://xunit.net/xunit.analyzers/rules/xUnit2020)
+ (ExpectUtf8Data.Value ? "UTF8 bytes" : "string"));
}
Assert.True(actual.Message.DataUtf8Bytes.Equals(expected.Message.DataUtf8Bytes));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ public void CanRestartStream(bool resetBackoff)

var backoffs = new List<TimeSpan>();

// On .NET Framework, cancelling a stream read can surface as an IOException
// rather than OperationCanceledException, which causes an Error event to fire
// before the Closed event. We skip these transient error events since they are
// an expected side effect of cancellation on that platform.
Func<EventSink.Action, bool> skipCancellationErrors = a => a.Kind == "Error";

using (var server = HttpServer.Start(handler))
{
using (var es = MakeEventSource(server.Uri, config => config.InitialRetryDelay(initialDelay)))
Expand All @@ -225,6 +231,7 @@ public void CanRestartStream(bool resetBackoff)
es.Restart(resetBackoff);

sink.ExpectActions(
skipCancellationErrors,
EventSink.ClosedAction(),
EventSink.OpenedAction(),
EventSink.MessageReceivedAction(anEvent)
Expand Down
Loading