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( () => 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(() => JobStateMachine.EnsureTransition( JobStateMachine.Cancelled, JobStateMachine.DownloadingInputs, JobTransitionMode.Recovery)); } }