Skip to content

Commit

Permalink
Merge pull request #478 from JosephWoodward/ReplaceThreadSleep
Browse files Browse the repository at this point in the history
Replace Thread.Sleep with Task.Wait
  • Loading branch information
josephwoodward committed Jan 22, 2018
2 parents c1fcfac + f07187d commit 4c6d30f
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 14 deletions.
3 changes: 3 additions & 0 deletions package/artifacts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nuget:Shouldly.3.0.0.nupkg
nugetSymbols:Shouldly.3.0.0.symbols.nupkg
releaseNotes:releasenotes.md
10 changes: 10 additions & 0 deletions package/releasenotes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- [#474](https://github.com/shouldly/shouldly/pull/474) - Fix broken ShouldHaveFlag tests contributed by Joseph Woodward ([JosephWoodward](https://github.com/JosephWoodward))
- [#468](https://github.com/shouldly/shouldly/pull/468) - Fix typos in SourceCodeTextGetter.cs contributed by David ([TAGC](https://github.com/TAGC))
- [#462](https://github.com/shouldly/shouldly/pull/462) - Correct VSTS/TFS environment variable. contributed by Gian Lorenzetto ([GianLorenzetto](https://github.com/GianLorenzetto))
- [#452](https://github.com/shouldly/shouldly/pull/452) - Update cake build script for new tooling contributed by Stuart Lang ([slang25](https://github.com/slang25))
- [#451](https://github.com/shouldly/shouldly/pull/451) - Fix build scripts contributed by Joseph Woodward ([JosephWoodward](https://github.com/JosephWoodward))
- [#446](https://github.com/shouldly/shouldly/pull/446) - Kill net35 with fire contributed by Stuart Lang ([slang25](https://github.com/slang25))
- [#439](https://github.com/shouldly/shouldly/pull/439) - Make diff tools configuration lazy contributed by Stuart Lang ([slang25](https://github.com/slang25))
- [#426](https://github.com/shouldly/shouldly/pull/426) - Added more ReSharper contract annotations contributed by Sebastian Krysmanski ([skrysmanski](https://github.com/skrysmanski))
- [#416](https://github.com/shouldly/shouldly/pull/416) - Fix for #415 (ShouldlyMethods attribute were missing on ShouldBeEnumE… contributed by Niklas Källander ([niklaskallander](https://github.com/niklaskallander))
- [#236](https://github.com/shouldly/shouldly/issues/236) - New logo
12 changes: 6 additions & 6 deletions src/Shouldly.Tests/ShouldCompleteInTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ public class ShouldCompleteInTests
[Fact]
public void ShouldCompleteIn_WhenFinishBeforeTimeout()
{
Should.NotThrow(() => Should.CompleteIn(() => Thread.Sleep(TimeSpan.FromSeconds(0.5)), TimeSpan.FromSeconds(5)));
Should.NotThrow(() => Should.CompleteIn(() => Task.Delay(TimeSpan.FromSeconds(0.5)).Wait(), TimeSpan.FromSeconds(5)));
}

[Fact]
public void ShouldCompleteIn_WhenFinishAfterTimeout()
{
var ex = Should.Throw<ShouldlyTimeoutException>(() =>
Should.CompleteIn(() => Thread.Sleep(TimeSpan.FromSeconds(5)), TimeSpan.FromSeconds(1), "Some additional context"));
Should.CompleteIn(() => Task.Delay(TimeSpan.FromSeconds(5)).Wait(), TimeSpan.FromSeconds(1), "Some additional context"));
ex.Message.ShouldContainWithoutWhitespace(@"
Delegate
should complete in
Expand All @@ -32,7 +32,7 @@ public void ShouldCompleteInTask_WhenFinishAfterTimeout()
{
var ex = Should.Throw<ShouldlyTimeoutException>(() =>
Should.CompleteIn(
() => Task.Factory.StartNew(() => Thread.Sleep(TimeSpan.FromSeconds(5))),
() => Task.Factory.StartNew(() => Task.Delay(TimeSpan.FromSeconds(5)).Wait()),
TimeSpan.FromSeconds(1), "Some additional context"));
ex.Message.ShouldContainWithoutWhitespace(@"
Task
Expand All @@ -54,7 +54,7 @@ public void ShouldCompleteInT_WhenFinishBeforeTimeout()
{
Should.NotThrow(() => Should.CompleteIn(() =>
{
Thread.Sleep(TimeSpan.FromSeconds(1));
Task.Delay(TimeSpan.FromSeconds(1)).Wait();
return "";
}, TimeSpan.FromSeconds(5)));
}
Expand All @@ -64,7 +64,7 @@ public void ShouldCompleteInT_WhenFinishAfterTimeout()
{
var ex = Should.Throw<ShouldlyTimeoutException>(() => Should.CompleteIn(() =>
{
Thread.Sleep(TimeSpan.FromSeconds(5));
Task.Delay(TimeSpan.FromSeconds(5)).Wait();
return "";
}, TimeSpan.FromSeconds(1), "Some additional context"));

Expand All @@ -84,7 +84,7 @@ public void ShouldCompleteInTaskT_WhenFinishAfterTimeout()
{
return Task.Factory.StartNew(() =>
{
Thread.Sleep(TimeSpan.FromSeconds(5));
Task.Delay(TimeSpan.FromSeconds(5)).Wait();
return "";
});
}, TimeSpan.FromSeconds(1), "Some additional context"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void ShouldThrowAWobbly()
{
var task = Task.Factory.StartNew(() =>
{
Thread.Sleep(5000);
Task.Delay(5000).Wait();
return "foo";
},
CancellationToken.None, TaskCreationOptions.None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class FuncOfTaskWithTimeoutScenario
[Fact]
public void ShouldThrowAWobbly()
{
var task = Task.Factory.StartNew(() => { Thread.Sleep(5000); },
var task = Task.Factory.StartNew(() => { Task.Delay(5000).Wait(); },
CancellationToken.None, TaskCreationOptions.None,
TaskScheduler.Default);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void ShouldThrowAWobbly()
{
var task = Task.Factory.StartNew(() =>
{
Thread.Sleep(5000);
Task.Delay(5000).Wait();
return "foo";
},
CancellationToken.None, TaskCreationOptions.None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class TaskWithTimeoutScenario
[Fact]
public void ShouldThrowAWobbly()
{
var task = Task.Factory.StartNew(() => { Thread.Sleep(5000); },
var task = Task.Factory.StartNew(() => { Task.Delay(5000).Wait(); },
CancellationToken.None, TaskCreationOptions.None,
TaskScheduler.Default);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class FuncOfTaskWithTimeoutScenario
[Fact]
public void ShouldThrowAWobbly()
{
var task = Task.Factory.StartNew(() => { Thread.Sleep(5000); },
var task = Task.Factory.StartNew(() => { Task.Delay(5000).Wait(); },
CancellationToken.None, TaskCreationOptions.None,
TaskScheduler.Default);

Expand All @@ -24,7 +24,7 @@ public void ShouldThrowAWobbly()
[Fact]
public void ShouldThrowAWobbly_ExceptionTypePassedIn()
{
var task = Task.Factory.StartNew(() => { Thread.Sleep(5000); },
var task = Task.Factory.StartNew(() => { Task.Delay(5000).Wait(); },
CancellationToken.None, TaskCreationOptions.None,
TaskScheduler.Default);

Expand Down
4 changes: 2 additions & 2 deletions src/Shouldly.Tests/ShouldThrow/TaskWithTimeoutScenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class TaskWithTimeoutScenario
[Fact]
public void ShouldThrowAWobbly()
{
var task = Task.Factory.StartNew(() => { Thread.Sleep(5000); },
var task = Task.Factory.StartNew(() => { Task.Delay(5000).Wait(); },
CancellationToken.None, TaskCreationOptions.None,
TaskScheduler.Default);

Expand All @@ -23,7 +23,7 @@ public void ShouldThrowAWobbly()
[Fact]
public void ShouldThrowAWobbly_ExceptionTypePassedIn()
{
var task = Task.Factory.StartNew(() => { Thread.Sleep(5000); },
var task = Task.Factory.StartNew(() => { Task.Delay(5000).Wait(); },
CancellationToken.None, TaskCreationOptions.None,
TaskScheduler.Default);

Expand Down

0 comments on commit 4c6d30f

Please sign in to comment.