Navigation Menu

Skip to content

Commit

Permalink
Fix race conditions on ShouldContainRefererHeader (#834)
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok committed Jan 4, 2019
1 parent 82a9b33 commit b9688e0
Showing 1 changed file with 8 additions and 0 deletions.
Expand Up @@ -9,6 +9,7 @@
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using PuppeteerSharp.Helpers;

namespace PuppeteerSharp.Tests.PageTests
{
Expand Down Expand Up @@ -64,14 +65,21 @@ public async Task ShouldContainRefererHeader()
{
await Page.SetRequestInterceptionAsync(true);
var requests = new List<Request>();
var requestsReadyTcs = new TaskCompletionSource<bool>();

Page.Request += async (sender, e) =>
{
await e.Request.ContinueAsync();
requests.Add(e.Request);
if (requests.Count > 1)
{
requestsReadyTcs.TrySetResult(true);
}
};

await Page.GoToAsync(TestConstants.ServerUrl + "/one-style.html");
await requestsReadyTcs.Task.WithTimeout();
Assert.Contains("/one-style.css", requests[1].Url);
Assert.Contains("/one-style.html", requests[1].Headers["Referer"]);
}
Expand Down

0 comments on commit b9688e0

Please sign in to comment.