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

improve accuracy of Expect100Continue_WaitsExpectedPeriodOfTimeBeforeSendingContent test #44053

Merged
merged 2 commits into from
Nov 3, 2020
Merged
Changes from 1 commit
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 @@ -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.Milliseconds);
}
}, 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 @@ -89,6 +89,7 @@ protected override void SerializeToStream(Stream stream, TransportContext contex
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
_tcs.SetResult(true);
Ticks = Environment.TickCount64;
return base.SerializeToStreamAsync(stream, context);
}
}
Expand Down