Skip to content

Commit 6550ab1

Browse files
authored
Merge pull request #31 from roederja2/also_wrap_start_work
* Also wrap start/stop work in suppress scope
2 parents 4d39c6e + 6ed087f commit 6550ab1

File tree

9 files changed

+105
-91
lines changed

9 files changed

+105
-91
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: csharp
2-
sudo: required
32
dist: xenial
3+
os: linux
44

55
branches:
66
except:
@@ -19,4 +19,3 @@ script:
1919
notifications:
2020
on_success: always
2121
on_failure: always
22-
on_start: always

Winton.Extensions.Threading.Actor.Tests.Unit/ActorTests.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -302,29 +302,29 @@ public async Task ShouldScheduleTaskAsLongRunningIfRequested(ActorEnqueueOptions
302302

303303
await actor.Start();
304304

305-
actor.Awaiting(async x => await x.Enqueue(() => ValidateActorThread(enqueueOptions), enqueueOptions)).ShouldNotThrow();
305+
actor.Awaiting(x => x.Enqueue(() => ValidateActorThread(enqueueOptions), enqueueOptions)).Should().NotThrow();
306306
actor.Awaiting(
307-
async x => await x.Enqueue(
307+
x => x.Enqueue(
308308
() =>
309309
{
310310
ValidateActorThread(enqueueOptions);
311311
return 676;
312-
}, enqueueOptions)).ShouldNotThrow();
312+
}, enqueueOptions)).Should().NotThrow();
313313
actor.Awaiting(
314-
async x => await x.Enqueue(
314+
x => x.Enqueue(
315315
async () =>
316316
{
317317
await Task.Yield();
318318
ValidateActorThread(enqueueOptions);
319-
}, enqueueOptions)).ShouldNotThrow();
319+
}, enqueueOptions)).Should().NotThrow();
320320
actor.Awaiting(
321-
async x => await x.Enqueue(
321+
x => x.Enqueue(
322322
async () =>
323323
{
324324
await Task.Yield();
325325
ValidateActorThread(enqueueOptions);
326326
return "moose";
327-
}, enqueueOptions)).ShouldNotThrow();
327+
}, enqueueOptions)).Should().NotThrow();
328328

329329
}
330330

@@ -507,7 +507,7 @@ int OffActorWork()
507507
stopTask.AwaitingShouldCompleteIn(_waitTimeout);
508508
break;
509509
case StopWorkOutcome.Faults:
510-
((Func<Task>)(async () => await stopTask)).ShouldThrow<InvalidOperationException>().WithMessage("Never meant to be");
510+
((Func<Task>)(async () => await stopTask)).Should().Throw<InvalidOperationException>().WithMessage("Never meant to be");
511511
break;
512512
default:
513513
throw new Exception($"Unhandled test case {stopWorkOutcome}.");
@@ -657,7 +657,7 @@ public void ShouldScheduleStartTaskAsLongRunningIfRequested(ActorEnqueueOptions
657657
}
658658
};
659659

660-
actor.Awaiting(async x => await x.Start()).ShouldNotThrow();
660+
actor.Awaiting(x => x.Start()).Should().NotThrow();
661661
}
662662

663663
[Theory]
@@ -675,7 +675,7 @@ public async Task ShouldScheduleStopTaskAsLongRunningIfRequested(ActorEnqueueOpt
675675

676676
await actor.Start();
677677

678-
actor.Awaiting(async x => await x.Stop()).ShouldNotThrow();
678+
actor.Awaiting(x => x.Stop()).Should().NotThrow();
679679
}
680680

681681
[Fact]
@@ -728,7 +728,7 @@ public void ShouldOnlyBeAbleToSpecifyStartWorkOnce()
728728
actor.StartWork = new ActorStartWork(() => { });
729729

730730
Action action = () => actor.StartWork = new ActorStartWork(() => { });
731-
action.ShouldThrow<InvalidOperationException>().WithMessage("Start work already specified.");
731+
action.Should().Throw<InvalidOperationException>().WithMessage("Start work already specified.");
732732
}
733733

734734
[Fact]
@@ -739,23 +739,23 @@ public void ShouldOnlyBeAbleToSpecifyStopWorkOnce()
739739
actor.StopWork = new ActorStopWork(() => { });
740740

741741
Action action = () => actor.StopWork = new ActorStopWork(() => { });
742-
action.ShouldThrow<InvalidOperationException>().WithMessage("Stop work already specified.");
742+
action.Should().Throw<InvalidOperationException>().WithMessage("Stop work already specified.");
743743
}
744744

745745
[Fact]
746746
public void ShouldNotBeAbleToSpecifyStartWorkOnceActorStarted()
747747
{
748748
var actor = CreateActor();
749749
Action action = () => actor.StartWork = new ActorStartWork(() => { });
750-
action.ShouldThrow<InvalidOperationException>().WithMessage("Start work cannot be specified after starting an actor.");
750+
action.Should().Throw<InvalidOperationException>().WithMessage("Start work cannot be specified after starting an actor.");
751751
}
752752

753753
[Fact]
754754
public void ShouldNotBeAbleToSpecifyStopWorkOnceActorStarted()
755755
{
756756
var actor = CreateActor();
757757
Action action = () => actor.StopWork = new ActorStopWork(() => { });
758-
action.ShouldThrow<InvalidOperationException>()
758+
action.Should().Throw<InvalidOperationException>()
759759
.WithMessage("Stop work cannot be specified after starting an actor.");
760760
}
761761

@@ -1007,7 +1007,7 @@ public async Task StopShouldNotRunStopWorkIfStartWorkFails()
10071007
StopWork = new ActorStopWork(() => stopWorkCalled = true)
10081008
};
10091009

1010-
actor.Awaiting(async x => await x.Start()).ShouldThrow<Exception>().WithMessage("Error.");
1010+
actor.Awaiting(x => x.Start()).Should().Throw<Exception>().WithMessage("Error.");
10111011

10121012
await actor.Stop();
10131013

@@ -1045,7 +1045,7 @@ private IActor CreateActor(Action<IActor> setup, ActorCreateOptions options = Ac
10451045

10461046
private static void ShouldBeCancelled(Task task)
10471047
{
1048-
Expect.That(async () => await task).ShouldThrow<TaskCanceledException>();
1048+
Expect.That(async () => await task).Should().Throw<OperationCanceledException>();
10491049
}
10501050

10511051
private void MarkAlreadyStopped()

Winton.Extensions.Threading.Actor.Tests.Unit/Internal/ActorTaskSchedulerTests.cs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,22 @@ public void FailureOfCriticalTaskShouldTerminateSchedulerWithSubsequentTasksBein
5656

5757
var task1 = _actorTaskFactory.StartNew(() => throw new Exception("oh dear"), CancellationToken.None, TaskCreationOptions.None, ActorTaskTraits.None);
5858

59-
task1.Awaiting(async x => await x).ShouldThrow<Exception>().WithMessage("oh dear");
59+
task1.Awaiting(x => x).Should().Throw<Exception>().WithMessage("oh dear");
6060

6161
_scheduler.TerminatedTask.Wait(TimeSpan.FromMilliseconds(250)).Should().BeFalse();
6262

6363
var task2 = _actorTaskFactory.StartNew(() => throw new Exception("no!!!"), CancellationToken.None, TaskCreationOptions.None, ActorTaskTraits.Critical);
6464
var task3 = _actorTaskFactory.StartNew(() => throw new Exception("shouldn't hit this"), CancellationToken.None, TaskCreationOptions.None, ActorTaskTraits.None);
6565

66-
task2.Awaiting(async x => await x).ShouldThrow<Exception>().WithMessage("no!!!");
66+
task2.Awaiting(x => x).Should().Throw<Exception>().WithMessage("no!!!");
6767

6868
ThrowIfWaitTimesOut(_scheduler.TerminatedTask);
6969

70-
task3.Awaiting(async x => await x).ShouldThrow<TaskCanceledException>();
70+
task3.Awaiting(x => x).Should().Throw<TaskCanceledException>();
7171

7272
var task4 = _actorTaskFactory.StartNew(() => throw new Exception("shouldn't hit this either"), CancellationToken.None, TaskCreationOptions.None, ActorTaskTraits.None);
7373

74-
task4.Awaiting(async x => await x).ShouldThrow<TaskCanceledException>();
74+
task4.Awaiting(x => x).Should().Throw<TaskCanceledException>();
7575
}
7676

7777
[Theory]
@@ -101,24 +101,24 @@ void TerminalWork()
101101
switch (terminalWorkOutcomeType)
102102
{
103103
case TaskStatus.Canceled:
104-
task1.Awaiting(async x => await x).ShouldThrow<TaskCanceledException>();
105-
_scheduler.TerminatedTask.Awaiting(async x => await x).ShouldThrow<TaskCanceledException>();
104+
task1.Awaiting(x => x).Should().Throw<TaskCanceledException>();
105+
_scheduler.TerminatedTask.Awaiting(x => x).Should().Throw<TaskCanceledException>();
106106
break;
107107
case TaskStatus.Faulted:
108-
task1.Awaiting(async x => await x).ShouldThrow<Exception>().WithMessage("oh dear");
109-
_scheduler.TerminatedTask.Awaiting(async x => await x).ShouldThrow<Exception>().WithMessage("oh dear");
108+
task1.Awaiting(x => x).Should().Throw<Exception>().WithMessage("oh dear");
109+
_scheduler.TerminatedTask.Awaiting(x => x).Should().Throw<Exception>().WithMessage("oh dear");
110110
break;
111111
case TaskStatus.RanToCompletion:
112-
task1.Awaiting(async x => await x).ShouldNotThrow();
113-
_scheduler.TerminatedTask.Awaiting(async x => await x).ShouldNotThrow();
112+
task1.Awaiting(x => x).Should().NotThrow();
113+
_scheduler.TerminatedTask.Awaiting(x => x).Should().NotThrow();
114114
break;
115115
}
116116

117-
task2.Awaiting(async x => await x).ShouldThrow<TaskCanceledException>();
117+
task2.Awaiting(x => x).Should().Throw<TaskCanceledException>();
118118

119119
var task3 = _actorTaskFactory.StartNew(() => throw new Exception("shouldn't hit this either"), CancellationToken.None, TaskCreationOptions.None, ActorTaskTraits.None);
120120

121-
task3.Awaiting(async x => await x).ShouldThrow<TaskCanceledException>();
121+
task3.Awaiting(x => x).Should().Throw<TaskCanceledException>();
122122
}
123123

124124
[Fact]
@@ -326,7 +326,7 @@ public void ShouldBeAbleToTerminateSchedulerSuchThatNoFurtherTasksAreExecuted(Ta
326326
lateTask = _actorTaskFactory.StartNew(() => { }, CancellationToken.None, TaskCreationOptions.None);
327327
}
328328

329-
lateTask.Awaiting(async x => await x).ShouldThrow<TaskCanceledException>();
329+
lateTask.Awaiting(x => x).Should().Throw<TaskCanceledException>();
330330
}
331331

332332
[Fact]
@@ -438,17 +438,19 @@ private void ThrowIfWaitTimesOut(Task task)
438438
{
439439
var timeout = Task.Delay(_waitTimeout);
440440

441-
Task.WhenAny(timeout, task).Awaiting(async x =>
442-
{
443-
var firstToFinish = await x.ConfigureAwait(false);
441+
async Task Action(Task<Task> x)
442+
{
443+
var firstToFinish = await x.ConfigureAwait(false);
444444

445-
if (firstToFinish == timeout)
446-
{
447-
throw new TimeoutException("Timed out awaiting task completion.");
448-
}
445+
if (firstToFinish == timeout)
446+
{
447+
throw new TimeoutException("Timed out awaiting task completion.");
448+
}
449+
450+
await firstToFinish.ConfigureAwait(false);
451+
}
449452

450-
await firstToFinish.ConfigureAwait(false);
451-
}).ShouldNotThrow();
453+
Task.WhenAny(timeout, task).Awaiting(Action).Should().NotThrow();
452454
}
453455

454456
private void UnpauseScheduler()

Winton.Extensions.Threading.Actor.Tests.Unit/Internal/ActorWorkSchedulerTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void ShouldBeAbleToSpecifyThatSyncWorkIsLongRunning()
108108
}
109109
}, TimeSpan.FromMilliseconds(1000), ActorScheduleOptions.NoInitialDelay | ActorScheduleOptions.WorkIsLongRunning);
110110

111-
taskCompletionSource.Awaiting(async x => await x.Task).ShouldNotThrow();
111+
taskCompletionSource.Awaiting(x => x.Task).Should().NotThrow();
112112
}
113113

114114
[Fact]
@@ -132,7 +132,7 @@ public void ShouldBeAbleToSpecifyThatAsyncWorkIsLongRunning()
132132
}
133133
}, TimeSpan.FromMilliseconds(1000), ActorScheduleOptions.NoInitialDelay | ActorScheduleOptions.WorkIsLongRunning);
134134

135-
taskCompletionSource.Awaiting(async x => await x.Task).ShouldNotThrow();
135+
taskCompletionSource.Awaiting(x => x.Task).Should().NotThrow();
136136
}
137137

138138
[Theory]
@@ -326,7 +326,7 @@ public void WhenAnUnhandledErrorOccursInTheWorkTheScheduleShouldStopAndEmitTheEr
326326
throw new Exception($"Unhandled test case {workType}.");
327327
}
328328

329-
Expect.That(async () => await task).ShouldThrow<Exception>().WithMessage("Pah!");
329+
Expect.That(async () => await task).Should().Throw<Exception>().WithMessage("Pah!");
330330

331331
// The schedule should have been cancelled so expect the times list to not be added to
332332
For.OneSecond(() => times.Should().HaveCount(3));
@@ -336,31 +336,31 @@ public void WhenAnUnhandledErrorOccursInTheWorkTheScheduleShouldStopAndEmitTheEr
336336
public void SynchronousSchedulerExtensionShouldEmitAnyArgumentOutOfRangeExceptions()
337337
{
338338
Expect.That(() => _scheduler.Schedule(() => { }, TimeSpan.Zero, ActorScheduleOptions.Default, x => { }))
339-
.ShouldThrow<ArgumentOutOfRangeException>()
339+
.Should().Throw<ArgumentOutOfRangeException>()
340340
.And.ParamName.Should().Be("interval");
341341
}
342342

343343
[Fact]
344344
public void SynchronousSchedulerExtensionShouldEmitAnyArgumentNullExceptions()
345345
{
346346
Expect.That(() => _scheduler.Schedule((Action)null, TimeSpan.FromDays(1), ActorScheduleOptions.Default, x => { }))
347-
.ShouldThrow<ArgumentNullException>()
347+
.Should().Throw<ArgumentNullException>()
348348
.And.ParamName.Should().Be("work");
349349
}
350350

351351
[Fact]
352352
public void AsynchronousSchedulerExtensionShouldEmitAnyArgumentOutOfRangeExceptions()
353353
{
354354
Expect.That(() => _scheduler.Schedule(async () => { await Task.Delay(10); }, TimeSpan.Zero, ActorScheduleOptions.Default, x => { }))
355-
.ShouldThrow<ArgumentOutOfRangeException>()
355+
.Should().Throw<ArgumentOutOfRangeException>()
356356
.And.ParamName.Should().Be("interval");
357357
}
358358

359359
[Fact]
360360
public void AsynchronousSchedulerExtensionShouldEmitAnyArgumentNullExceptions()
361361
{
362362
Expect.That(() => _scheduler.Schedule(null, TimeSpan.FromDays(1), ActorScheduleOptions.Default, x => { }))
363-
.ShouldThrow<ArgumentNullException>()
363+
.Should().Throw<ArgumentNullException>()
364364
.And.ParamName.Should().Be("work");
365365
}
366366
}

Winton.Extensions.Threading.Actor.Tests.Unit/Winton.Extensions.Threading.Actor.Tests.Unit.csproj

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp2.0;net462</TargetFrameworks>
4+
<TargetFrameworks>netcoreapp2.1;net462</TargetFrameworks>
55
<SignAssembly>True</SignAssembly>
66
<DelaySign>False</DelaySign>
77
<AssemblyOriginatorKeyFile>../keys/Winton.Extensions.Threading.Actor.snk</AssemblyOriginatorKeyFile>
@@ -10,10 +10,13 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.0" />
14-
<PackageReference Include="Moq" Version="4.8.1" />
15-
<PackageReference Include="xunit" Version="2.3.1" />
16-
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
14+
<PackageReference Include="Moq" Version="4.14.3" />
15+
<PackageReference Include="xunit" Version="2.4.1" />
16+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
17+
<PrivateAssets>all</PrivateAssets>
18+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19+
</PackageReference>
1720
</ItemGroup>
1821

1922
<ItemGroup>

Winton.Extensions.Threading.Actor.Tests.Utilities/FluentTaskExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ public static class FluentTaskExtensions
99
public static void AwaitingShouldCompleteIn(this Task self, TimeSpan waitTime, string because = "", params object[] becauseArgs)
1010
{
1111
Action action = self.Wait;
12-
action.ExecutionTime().ShouldNotExceed(waitTime, because, becauseArgs);
12+
action.ExecutionTime().Should().BeLessThan(waitTime, because, becauseArgs);
1313
}
1414

1515
public static AndConstraint<T> AwaitingShouldCompleteIn<T>(this Task<T> self, TimeSpan waitTime, string because = "", params object[] becauseArgs)
1616
{
1717
Action action = self.Wait;
18-
action.ExecutionTime().ShouldNotExceed(waitTime, because, becauseArgs);
18+
action.ExecutionTime().Should().BeLessThan(waitTime, because, becauseArgs);
1919
return new AndConstraint<T>(self.Result);
2020
}
2121
}

Winton.Extensions.Threading.Actor.Tests.Utilities/Winton.Extensions.Threading.Actor.Tests.Utilities.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</PropertyGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="FluentAssertions" Version="4.19.4" />
20+
<PackageReference Include="FluentAssertions" Version="5.10.3" />
2121
</ItemGroup>
2222

2323
</Project>

0 commit comments

Comments
 (0)