Permalink
Browse files

TextConsole - BreaksOutOfLoopAfterCancellation

  • Loading branch information...
bobbymcr committed Nov 30, 2018
1 parent 558f97e commit 20e8d37388c9deeb1c36f98533bf1f4a3efffb13
Showing with 26 additions and 1 deletion.
  1. +1 −1 core/src/TextConsole.cs
  2. +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

Please sign in to comment.