Permalink
Browse files
TextConsole - BreaksOutOfLoopAfterCancellation
- Loading branch information...
Showing
with
26 additions
and
1 deletion.
-
+1
−1
core/src/TextConsole.cs
-
+25
−0
core/test/TextConsoleTest.cs
|
@@ -33,7 +33,7 @@ public void Run(CancellationToken token) |
|
|
|
this.bus.Send(new InputMessage(line)); |
|
|
|
} |
|
|
|
} |
|
|
|
while (line != null); |
|
|
|
while (!token.IsCancellationRequested && (line != null)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@@ -50,5 +50,30 @@ public void ProducesNoOutputAfterRun() |
|
|
|
|
|
|
|
output.ToString().Should().BeEmpty(); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void BreaksOutOfLoopAfterCancellation() |
|
|
|
{ |
|
|
|
using (CancellationTokenSource cts = new CancellationTokenSource()) |
|
|
|
{ |
|
|
|
MessageBus bus = new MessageBus(); |
|
|
|
int calls = 0; |
|
|
|
Action<InputMessage> subscriber = m => |
|
|
|
{ |
|
|
|
++calls; |
|
|
|
if (m.Line == "cancel") |
|
|
|
{ |
|
|
|
cts.Cancel(); |
|
|
|
} |
|
|
|
}; |
|
|
|
bus.Subscribe(subscriber); |
|
|
|
string[] lines = new string[] { "start", "cancel", "too late" }; |
|
|
|
TextConsole con = new TextConsole(bus, new StringReader(string.Join(Environment.NewLine, lines)), TextWriter.Null); |
|
|
|
|
|
|
|
con.Run(cts.Token); |
|
|
|
|
|
|
|
calls.Should().Be(2); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
0 comments on commit
20e8d37