Skip to content

Commit

Permalink
Minor QUIC test improvements (#55494)
Browse files Browse the repository at this point in the history
* reduce timeout in SetListenerTimeoutWorksWithSmallTimeout

* replace AssertArrayEqual with AssertExtensions.SequenceEqual

Co-authored-by: Geoffrey Kizer <geoffrek@windows.microsoft.com>
  • Loading branch information
geoffkizer and Geoffrey Kizer authored Jul 12, 2021
1 parent f463d8d commit e4cc8f9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 40 deletions.
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

0 comments on commit e4cc8f9

Please sign in to comment.