Skip to content

Commit 287f033

Browse files
author
Jos Hickson
committed
Get Travis and Appveyor working.
1 parent 135dd6f commit 287f033

15 files changed

Lines changed: 386 additions & 275 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717
!*.snk
1818
!*.bat
1919
!*.sh
20+
!*.yml
21+
!*.ps1
22+
2023
bin/
2124
obj/
2225
/.vs/
2326
/.vscode/
2427
Version.targets
28+
travis.props

.travis.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
language: csharp
2+
3+
sudo: required
4+
5+
os: linux
6+
7+
dist: trusty
8+
9+
branches:
10+
except:
11+
- /^[0-9]/
12+
13+
dotnet: 1.0.1
14+
15+
mono: none
16+
17+
script:
18+
- (git fetch --unshallow 2>/dev/null || echo "Already full repo.")
19+
- ./build.sh
20+
21+
notifications:
22+
on_success: always
23+
on_failure: always
24+
on_start: always

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

Lines changed: 79 additions & 81 deletions
Large diffs are not rendered by default.

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

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
using System.Collections.Generic;
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using FluentAssertions;
89
using Moq;
9-
using Shouldly;
1010
using Winton.Extensions.Threading.Actor.Internal;
1111
using Winton.Extensions.Threading.Actor.Tests.Utilities;
1212
using Xunit;
@@ -54,8 +54,8 @@ public void ForLongRunningTasksShouldUseActiveThreadIfNotFromThreadPool()
5454
barrier.SetResult(true);
5555
ThrowIfWaitTimesOut(task2);
5656

57-
Should.NotThrow(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnThreadPoolThread(It.IsAny<Action>()), Times.Never));
58-
Should.NotThrow(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnNonThreadPoolThread(It.IsAny<Action>()), Times.Once));
57+
Expect.That(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnThreadPoolThread(It.IsAny<Action>()), Times.Never)).ShouldNotThrow();
58+
Expect.That(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnNonThreadPoolThread(It.IsAny<Action>()), Times.Once)).ShouldNotThrow();
5959
}
6060

6161
[Fact]
@@ -68,10 +68,11 @@ public void ForLongRunningTasksShouldUseNonThreadPoolThreadIfActiveThreadFromThr
6868
shortTask.Start(_scheduler);
6969
longTask.Start(_scheduler);
7070
barrier.SetResult(true);
71-
Should.CompleteIn(longTask, _waitTimeout);
7271

73-
Should.NotThrow(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnThreadPoolThread(It.IsAny<Action>()), Times.Once));
74-
Should.NotThrow(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnNonThreadPoolThread(It.IsAny<Action>()), Times.Once));
72+
longTask.AwaitingShouldCompleteIn(_waitTimeout);
73+
74+
Expect.That(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnThreadPoolThread(It.IsAny<Action>()), Times.Once)).ShouldNotThrow();
75+
Expect.That(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnNonThreadPoolThread(It.IsAny<Action>()), Times.Once)).ShouldNotThrow();
7576
}
7677

7778
[Fact]
@@ -80,20 +81,20 @@ public void ForLongRunningTasksShouldUseNonThreadPoolThreadIfNoActiveThread()
8081
var task = _actorTaskFactory.Create(() => { }, CancellationToken.None, TaskCreationOptions.LongRunning);
8182
task.Start(_scheduler);
8283
ThrowIfWaitTimesOut(task);
83-
Should.NotThrow(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnThreadPoolThread(It.IsAny<Action>()), Times.Never));
84-
Should.NotThrow(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnNonThreadPoolThread(It.IsAny<Action>()), Times.Once));
84+
Expect.That(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnThreadPoolThread(It.IsAny<Action>()), Times.Never)).ShouldNotThrow();
85+
Expect.That(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnNonThreadPoolThread(It.IsAny<Action>()), Times.Once)).ShouldNotThrow();
8586
}
8687

8788
[Fact]
8889
public void ForLongRunningTasksThreadShouldBeMarkedAsActorThreadDuringExecution()
8990
{
90-
Actor.CurrentId.ShouldBe(ActorId.None);
91+
Actor.CurrentId.Should().Be(ActorId.None);
9192
var actorIdOnWorkThread = new ActorId();
9293
var task = _actorTaskFactory.Create(() => { actorIdOnWorkThread = Actor.CurrentId; }, CancellationToken.None, TaskCreationOptions.None);
9394
task.Start(_scheduler);
9495
ThrowIfWaitTimesOut(task);
95-
Actor.CurrentId.ShouldBe(ActorId.None);
96-
actorIdOnWorkThread.ShouldBe(_actorId);
96+
Actor.CurrentId.Should().Be(ActorId.None);
97+
actorIdOnWorkThread.Should().Be(_actorId);
9798
}
9899

99100
[Fact]
@@ -108,8 +109,8 @@ public void ForNonLongRunningTasksShouldUseNewThreadPoolThreadIfActiveThreadFrom
108109
barrier.SetResult(true);
109110
ThrowIfWaitTimesOut(task2);
110111

111-
Should.NotThrow(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnThreadPoolThread(It.IsAny<Action>()), Times.Exactly(2)));
112-
Should.NotThrow(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnNonThreadPoolThread(It.IsAny<Action>()), Times.Never));
112+
Expect.That(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnThreadPoolThread(It.IsAny<Action>()), Times.Exactly(2))).ShouldNotThrow();
113+
Expect.That(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnNonThreadPoolThread(It.IsAny<Action>()), Times.Never)).ShouldNotThrow();
113114
}
114115

115116
[Fact]
@@ -124,8 +125,8 @@ public void ForNonLongRunningTasksShouldUseActiveThreadIfNotFromThreadPool()
124125
barrier.SetResult(true);
125126
ThrowIfWaitTimesOut(task2);
126127

127-
Should.NotThrow(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnThreadPoolThread(It.IsAny<Action>()), Times.Never));
128-
Should.NotThrow(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnNonThreadPoolThread(It.IsAny<Action>()), Times.Once));
128+
Expect.That(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnThreadPoolThread(It.IsAny<Action>()), Times.Never)).ShouldNotThrow();
129+
Expect.That(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnNonThreadPoolThread(It.IsAny<Action>()), Times.Once)).ShouldNotThrow();
129130
}
130131

131132
[Fact]
@@ -134,20 +135,20 @@ public void ForNonLongRunningTasksShouldUseThreadPoolThreadIfNoActiveThread()
134135
var task = _actorTaskFactory.Create(() => { }, CancellationToken.None, TaskCreationOptions.None);
135136
task.Start(_scheduler);
136137
ThrowIfWaitTimesOut(task);
137-
Should.NotThrow(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnThreadPoolThread(It.IsAny<Action>()), Times.Once));
138-
Should.NotThrow(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnNonThreadPoolThread(It.IsAny<Action>()), Times.Never));
138+
Expect.That(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnThreadPoolThread(It.IsAny<Action>()), Times.Once)).ShouldNotThrow();
139+
Expect.That(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnNonThreadPoolThread(It.IsAny<Action>()), Times.Never)).ShouldNotThrow();
139140
}
140141

141142
[Fact]
142143
public void ForNonLongRunningTasksThreadShouldBeMarkedAsActorThreadDuringExecution()
143144
{
144-
Actor.CurrentId.ShouldBe(ActorId.None);
145+
Actor.CurrentId.Should().Be(ActorId.None);
145146
var actorIdOnWorkThread = new ActorId();
146147
var task = _actorTaskFactory.Create(() => { actorIdOnWorkThread = Actor.CurrentId; }, CancellationToken.None, TaskCreationOptions.None);
147148
task.Start(_scheduler);
148149
ThrowIfWaitTimesOut(task);
149-
Actor.CurrentId.ShouldBe(ActorId.None);
150-
actorIdOnWorkThread.ShouldBe(_actorId);
150+
Actor.CurrentId.Should().Be(ActorId.None);
151+
actorIdOnWorkThread.Should().Be(_actorId);
151152
}
152153

153154
[Theory]
@@ -175,24 +176,25 @@ public void ShouldBeAbleToTerminateSchedulerSuchThatNoFurtherTasksAreExecuted(Ta
175176

176177
barrier.SetResult(true);
177178

178-
Should.CompleteIn(terminalTask, _waitTimeout);
179+
terminalTask.AwaitingShouldCompleteIn(_waitTimeout);
179180

180181
if (lateScheduleType == LateScheduleType.AfterTerminalTaskComplete)
181182
{
182183
Thread.Sleep(TimeSpan.FromMilliseconds(100));
183184
lateTask.Start(_scheduler);
184185
}
185186

186-
lateTask.Wait(TimeSpan.FromSeconds(2)).ShouldBeFalse();
187+
lateTask.Wait(TimeSpan.FromSeconds(2)).Should().BeFalse();
187188
}
188189

189190
[Fact]
190191
public void ShouldFailMiserablyIfTryToScheduleTaskThatIsNotAnActorTask()
191192
{
192193
var offensiveTask = new Task(() => { });
193-
Should.Throw<TaskSchedulerException>(() => offensiveTask.Start(_scheduler))
194-
.InnerException.ShouldBeOfType<InvalidOperationException>()
195-
.Message.ShouldBe("Task is not an actor task.");
194+
Expect.That(() => offensiveTask.Start(_scheduler))
195+
.ShouldThrow<TaskSchedulerException>()
196+
.WithInnerException<InvalidOperationException>()
197+
.WithInnerMessage("Task is not an actor task.");
196198
}
197199

198200
[Fact]
@@ -257,8 +259,8 @@ await Launch(x =>
257259

258260
await await task;
259261

260-
actorWorkIds.ShouldAllBe(x => x == _actorId);
261-
offActorWorkIds.ShouldAllBe(x => x == ActorId.None);
262+
actorWorkIds.Should().OnlyContain(x => x == _actorId);
263+
offActorWorkIds.Should().OnlyContain(x => x == ActorId.None);
262264
}
263265

264266
[Fact]
@@ -282,8 +284,9 @@ public void ShouldYieldCurrentThreadAndRerequestFromThreadPoolIfHaveProcessedNon
282284
fixableUtcTimeSource.Increment(TimeSpan.FromMilliseconds(250));
283285
barrier.SetResult(true);
284286

285-
Should.CompleteIn(task2, _waitTimeout);
286-
Should.NotThrow(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnThreadPoolThread(It.IsAny<Action>()), Times.Exactly(2)));
287+
task2.AwaitingShouldCompleteIn(_waitTimeout);
288+
289+
Expect.That(() => Mock.Get(_workItemQueuer).Verify(x => x.QueueOnThreadPoolThread(It.IsAny<Action>()), Times.Exactly(2))).ShouldNotThrow();
287290
}
288291

289292
private static void LaunchOnNonThreadPoolThread(Action action)

0 commit comments

Comments
 (0)