zcbot/windows-node/Zcbot.WindowsNode.Tests/JobStateMachineTests.cs

66 lines
2.1 KiB
C#

namespace Zcbot.WindowsNode.Tests;
public sealed class JobStateMachineTests
{
[Theory]
[InlineData("accepted", "downloading_inputs")]
[InlineData("downloading_inputs", "downloading_inputs")]
[InlineData("downloading_inputs", "ready_to_run")]
[InlineData("ready_to_run", "software_running")]
[InlineData("software_running", "uploading_outputs")]
[InlineData("uploading_outputs", "succeeded")]
[InlineData("accepted", "cancelled")]
[InlineData("software_running", "failed")]
public void NormalTransitionsAcceptThePersistedExecutionFlow(string current, string next)
{
JobStateMachine.EnsureTransition(current, next);
}
[Theory]
[InlineData("ready_to_run", "downloading_inputs")]
[InlineData("software_running", "ready_to_run")]
[InlineData("succeeded", "uploading_outputs")]
[InlineData("failed", "failed")]
[InlineData("unknown", "accepted")]
public void NormalTransitionsRejectBackwardsTerminalAndUnknownChanges(
string current,
string next)
{
Assert.Throws<InvalidDataException>(
() => JobStateMachine.EnsureTransition(current, next));
}
[Theory]
[InlineData("ready_to_run")]
[InlineData("software_running")]
[InlineData("uploading_outputs")]
public void RecoveryMayReenterIdempotentInputVerification(string current)
{
JobStateMachine.EnsureTransition(
current,
JobStateMachine.DownloadingInputs,
JobTransitionMode.Recovery);
}
[Theory]
[InlineData("accepted")]
[InlineData("ready_to_run")]
[InlineData("software_running")]
public void RecoveryMayResumeUploadFromHistoricalLocalState(string current)
{
JobStateMachine.EnsureTransition(
current,
JobStateMachine.UploadingOutputs,
JobTransitionMode.Recovery);
}
[Fact]
public void RecoveryCannotReopenATerminalStage()
{
Assert.Throws<InvalidDataException>(() => JobStateMachine.EnsureTransition(
JobStateMachine.Cancelled,
JobStateMachine.DownloadingInputs,
JobTransitionMode.Recovery));
}
}