Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor QUIC test improvements #55494

Merged
merged 2 commits into from
Jul 12, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public async Task WaitForAvailableBidirectionStreamsAsyncWorks()
public async Task SetListenerTimeoutWorksWithSmallTimeout()
{
var quicOptions = new QuicListenerOptions();
quicOptions.IdleTimeout = TimeSpan.FromSeconds(10);
quicOptions.IdleTimeout = TimeSpan.FromSeconds(1);
quicOptions.ServerAuthenticationOptions = GetSslServerAuthenticationOptions();
quicOptions.ListenEndPoint = new IPEndPoint(IPAddress.Loopback, 0);

Expand Down Expand Up @@ -476,7 +476,7 @@ await RunClientServer(
byte[] buffer = new byte[data.Length];
int bytesRead = await ReadAll(stream, buffer);
Assert.Equal(data.Length, bytesRead);
AssertArrayEqual(data, buffer);
AssertExtensions.SequenceEqual(data, buffer);

for (int pos = 0; pos < data.Length; pos += writeSize)
{
Expand All @@ -499,7 +499,7 @@ await RunClientServer(
byte[] buffer = new byte[data.Length];
int bytesRead = await ReadAll(stream, buffer);
Assert.Equal(data.Length, bytesRead);
AssertArrayEqual(data, buffer);
AssertExtensions.SequenceEqual(data, buffer);

await stream.ShutdownCompleted();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ await RunClientServer(
byte[] buffer = new byte[data.Length];
int bytesRead = await ReadAll(stream, buffer);
Assert.Equal(data.Length, bytesRead);
AssertArrayEqual(data, buffer);
AssertExtensions.SequenceEqual(data, buffer);

for (int pos = 0; pos < data.Length; pos += writeSize)
{
Expand All @@ -213,7 +213,7 @@ await RunClientServer(
byte[] buffer = new byte[data.Length];
int bytesRead = await ReadAll(stream, buffer);
Assert.Equal(data.Length, bytesRead);
AssertArrayEqual(data, buffer);
AssertExtensions.SequenceEqual(data, buffer);

await stream.ShutdownCompleted();
}
Expand Down Expand Up @@ -391,7 +391,7 @@ await RunClientServer(
}

Assert.Equal(testBuffer.Length, totalBytesRead);
AssertArrayEqual(testBuffer, receiveBuffer);
AssertExtensions.SequenceEqual(testBuffer, receiveBuffer);

await serverStream.ShutdownCompleted();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,40 +171,6 @@ internal static async Task<int> WriteForever(QuicStream stream)
await stream.WriteAsync(buffer);
}
}

internal static void AssertArrayEqual(byte[] expected, byte[] actual)
{
for (int i = 0; i < expected.Length; ++i)
{
if (expected[i] == actual[i])
{
continue;
}

var message = $"Wrong data starting from idx={i}\n" +
$"Expected: {ToStringAroundIndex(expected, i)}\n" +
$"Actual: {ToStringAroundIndex(actual, i)}";

Assert.True(expected[i] == actual[i], message);
}
}

private static string ToStringAroundIndex(byte[] arr, int idx, int dl = 3, int dr = 7)
{
var sb = new StringBuilder(idx - (dl+1) >= 0 ? "[..., " : "[");

for (int i = idx - dl; i <= idx + dr; ++i)
{
if (i >= 0 && i < arr.Length)
{
sb.Append($"{arr[i]}, ");
}
}

sb.Append(idx + (dr+1) < arr.Length ? "...]" : "]");

return sb.ToString();
}
}

public interface IQuicImplProviderFactory
Expand Down