Skip to content

Commit

Permalink
troubleshoot test that's failing only on AppVeyor
Browse files Browse the repository at this point in the history
  • Loading branch information
tmenier committed Mar 21, 2019
1 parent 6606981 commit 529d25a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ TestResult.xml
*.bak
.idea
lcov.info
coverage.json
5 changes: 5 additions & 0 deletions Flurl.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{B6BF9238
ProjectSection(SolutionItems) = preProject
appveyor.yml = appveyor.yml
Build\build.cmd = Build\build.cmd
Build\build.sh = Build\build.sh
Build\Flurl.netstandard.sln = Build\Flurl.netstandard.sln
Build\test.cmd = Build\test.cmd
Build\test.coverage.cmd = Build\test.coverage.cmd
Build\test.coverage.sh = Build\test.coverage.sh
Build\test.sh = Build\test.sh
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PackageTester.NET45", "PackageTesters\PackageTester.NET45\PackageTester.NET45.csproj", "{63FD500A-7449-46E6-92C3-24CE92E817C7}"
Expand Down
13 changes: 6 additions & 7 deletions Test/Flurl.Test/Http/FlurlClientFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,33 @@ public void can_configure_client_from_factory() {
}

[Test]
public void ConfigureClient_is_thread_safe() {
public async Task ConfigureClient_is_thread_safe() {
var fac = new PerHostFlurlClientFactory();

var sequence = new List<int>();

var task1 = Task.Run(() => fac.ConfigureClient("http://api.com", c => {
sequence.Add(1);
Thread.Sleep(200);
Thread.Sleep(200);
sequence.Add(3);
}));

Thread.Sleep(50);
await Task.Delay(50);

// modifies same client as task1, should get blocked until task1 is done
var task2 = Task.Run(() => fac.ConfigureClient("http://api.com", c => {
sequence.Add(4);
}));

Thread.Sleep(50);
await Task.Delay(50);

// modifies different client, should run immediately
var task3 = Task.Run(() => fac.ConfigureClient("http://api2.com", c => {
sequence.Add(2);
}));


Task.WaitAll(task1, task2, task3);
CollectionAssert.AreEqual(new[] { 1, 2, 3, 4 }, sequence);
await Task.WhenAll(task1, task2, task3);
Assert.AreEqual("1,2,3,4", string.Join(",", sequence));
}
}
}

0 comments on commit 529d25a

Please sign in to comment.