mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-31 03:11:07 +02:00
Improved test timing for CommandExecutor.
This commit is contained in:
parent
e01e822394
commit
090dd45541
@ -35,6 +35,15 @@ public void Setup()
|
||||
.Returns(_executorB.Object);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
Subject.Handle(new ApplicationShutdownRequested());
|
||||
|
||||
// Give the threads a bit of time to shut down.
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
|
||||
private void GivenCommandQueue()
|
||||
{
|
||||
_commandQueue = new BlockingCollection<CommandModel>(new CommandQueue());
|
||||
@ -44,8 +53,10 @@ private void GivenCommandQueue()
|
||||
.Returns(_commandQueue.GetConsumingEnumerable);
|
||||
}
|
||||
|
||||
private void WaitForExecution(CommandModel commandModel)
|
||||
private void QueueAndWaitForExecution(CommandModel commandModel)
|
||||
{
|
||||
Thread.Sleep(10);
|
||||
|
||||
Mocker.GetMock<IManageCommandQueue>()
|
||||
.Setup(s => s.Complete(It.Is<CommandModel>(c => c == commandModel), It.IsAny<string>()))
|
||||
.Callback(() => _commandExecuted = true);
|
||||
@ -54,12 +65,14 @@ private void WaitForExecution(CommandModel commandModel)
|
||||
.Setup(s => s.Fail(It.Is<CommandModel>(c => c == commandModel), It.IsAny<string>(), It.IsAny<Exception>()))
|
||||
.Callback(() => _commandExecuted = true);
|
||||
|
||||
_commandQueue.Add(commandModel);
|
||||
|
||||
while (!_commandExecuted)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
|
||||
var t1 = 1;
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -82,9 +95,8 @@ public void should_execute_on_executor()
|
||||
};
|
||||
|
||||
Subject.Handle(new ApplicationStartedEvent());
|
||||
_commandQueue.Add(commandModel);
|
||||
|
||||
WaitForExecution(commandModel);
|
||||
QueueAndWaitForExecution(commandModel);
|
||||
|
||||
_executorA.Verify(c => c.Execute(commandA), Times.Once());
|
||||
}
|
||||
@ -100,9 +112,8 @@ public void should_not_execute_on_incompatible_executor()
|
||||
};
|
||||
|
||||
Subject.Handle(new ApplicationStartedEvent());
|
||||
_commandQueue.Add(commandModel);
|
||||
|
||||
WaitForExecution(commandModel);
|
||||
QueueAndWaitForExecution(commandModel);
|
||||
|
||||
_executorA.Verify(c => c.Execute(commandA), Times.Once());
|
||||
_executorB.Verify(c => c.Execute(It.IsAny<CommandB>()), Times.Never());
|
||||
@ -122,9 +133,8 @@ public void broken_executor_should_publish_executed_event()
|
||||
.Throws(new NotImplementedException());
|
||||
|
||||
Subject.Handle(new ApplicationStartedEvent());
|
||||
_commandQueue.Add(commandModel);
|
||||
|
||||
WaitForExecution(commandModel);
|
||||
QueueAndWaitForExecution(commandModel);
|
||||
|
||||
VerifyEventPublished<CommandExecutedEvent>();
|
||||
ExceptionVerification.ExpectedErrors(1);
|
||||
@ -141,9 +151,8 @@ public void should_publish_executed_event_on_success()
|
||||
};
|
||||
|
||||
Subject.Handle(new ApplicationStartedEvent());
|
||||
_commandQueue.Add(commandModel);
|
||||
|
||||
WaitForExecution(commandModel);
|
||||
QueueAndWaitForExecution(commandModel);
|
||||
|
||||
VerifyEventPublished<CommandExecutedEvent>();
|
||||
}
|
||||
@ -159,9 +168,8 @@ public void should_use_completion_message()
|
||||
};
|
||||
|
||||
Subject.Handle(new ApplicationStartedEvent());
|
||||
_commandQueue.Add(commandModel);
|
||||
|
||||
WaitForExecution(commandModel);
|
||||
QueueAndWaitForExecution(commandModel);
|
||||
|
||||
Mocker.GetMock<IManageCommandQueue>()
|
||||
.Setup(s => s.Complete(It.Is<CommandModel>(c => c == commandModel), commandA.CompletionMessage))
|
||||
@ -180,9 +188,8 @@ public void should_use_last_progress_message_if_completion_message_is_null()
|
||||
};
|
||||
|
||||
Subject.Handle(new ApplicationStartedEvent());
|
||||
_commandQueue.Add(commandModel);
|
||||
|
||||
WaitForExecution(commandModel);
|
||||
QueueAndWaitForExecution(commandModel);
|
||||
|
||||
Mocker.GetMock<IManageCommandQueue>()
|
||||
.Setup(s => s.Complete(It.Is<CommandModel>(c => c == commandModel), commandModel.Message))
|
||||
@ -202,10 +209,10 @@ public class CommandB : Command
|
||||
|
||||
public CommandB()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override string CompletionMessage => null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user