Skip to content

Commit

Permalink
improve accuracy of Expect100Continue_WaitsExpectedPeriodOfTimeBefore…
Browse files Browse the repository at this point in the history
…SendingContent test (dotnet#44053)

* improve accuracy of Expect100Continue_WaitsExpectedPeriodOfTimeBeforeSendingContent test

* feedback from review
  • Loading branch information
wfurt authored Nov 3, 2020
1 parent 5dcbc84 commit 6ca1f20
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ await LoopbackServer.CreateClientAndServerAsync(async uri =>
var request = new HttpRequestMessage(HttpMethod.Post, uri) { Content = content, Version = UseVersion };
request.Headers.ExpectContinue = true;

var sw = Stopwatch.StartNew();
long start = Environment.TickCount64;
(await invoker.SendAsync(TestAsync, request, default)).Dispose();
sw.Stop();

Assert.InRange(sw.Elapsed, delay - TimeSpan.FromSeconds(.5), delay * 20); // arbitrary wiggle room
long elapsed = content.Ticks - start;
Assert.True(elapsed >= delay.TotalMilliseconds);
}
}, async server =>
{
Expand All @@ -80,6 +79,7 @@ await server.AcceptConnectionAsync(async connection =>
private sealed class SetTcsContent : StreamContent
{
private readonly TaskCompletionSource<bool> _tcs;
public long Ticks;

public SetTcsContent(Stream stream, TaskCompletionSource<bool> tcs) : base(stream) => _tcs = tcs;

Expand All @@ -88,6 +88,7 @@ protected override void SerializeToStream(Stream stream, TransportContext contex

protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
Ticks = Environment.TickCount64;
_tcs.SetResult(true);
return base.SerializeToStreamAsync(stream, context);
}
Expand Down

0 comments on commit 6ca1f20

Please sign in to comment.