Best Coyote code snippet using Microsoft.Coyote.Actors.BugFinding.Tests.OnHaltTests.OnInitializeAsync
OnHaltTests.cs
Source:OnHaltTests.cs
...23 }24 }25 private class A1 : Actor26 {27 protected override Task OnInitializeAsync(Event initialEvent)28 {29 this.SendEvent(this.Id, HaltEvent.Instance);30 return Task.CompletedTask;31 }32 protected override Task OnHaltAsync(Event e)33 {34 this.Assert(false, "Reached test assertion.");35 return Task.CompletedTask;36 }37 }38 [Fact(Timeout = 5000)]39 public void TestOnHaltAsyncAfterSendInActor()40 {41 this.TestWithError(r =>42 {43 r.CreateActor(typeof(A1));44 },45 expectedError: "Reached test assertion.",46 replay: true);47 }48 private class M1 : StateMachine49 {50 [Start]51 [OnEntry(nameof(InitOnEntry))]52 private class Init : State53 {54 }55 private void InitOnEntry()56 {57 this.SendEvent(this.Id, HaltEvent.Instance);58 }59 protected override Task OnHaltAsync(Event e)60 {61 this.Assert(false, "Reached test assertion.");62 return Task.CompletedTask;63 }64 }65 [Fact(Timeout = 5000)]66 public void TestOnHaltAsyncAfterSendInStateMachine()67 {68 this.TestWithError(r =>69 {70 r.CreateActor(typeof(M1));71 },72 expectedError: "Reached test assertion.",73 replay: true);74 }75 private class M2 : StateMachine76 {77 [Start]78 [OnEntry(nameof(InitOnEntry))]79 private class Init : State80 {81 }82 private void InitOnEntry() => this.RaiseHaltEvent();83 protected override Task OnHaltAsync(Event e)84 {85 this.Assert(false, "Reached test assertion.");86 return Task.CompletedTask;87 }88 }89 [Fact(Timeout = 5000)]90 public void TestOnHaltAsyncAfterRaiseInStateMachine()91 {92 this.TestWithError(r =>93 {94 r.CreateActor(typeof(M2));95 },96 expectedError: "Reached test assertion.",97 replay: true);98 }99 private class A3 : Actor100 {101 protected override Task OnInitializeAsync(Event initialEvent)102 {103 this.SendEvent(this.Id, HaltEvent.Instance);104 return Task.CompletedTask;105 }106 protected override async Task OnHaltAsync(Event e)107 {108 await this.ReceiveEventAsync(typeof(Event));109 }110 }111 [Fact(Timeout = 5000)]112 public void TestOnHaltAsyncWithReceiveInActor()113 {114 this.TestWithError(r =>115 {116 r.CreateActor(typeof(A3));117 },118 expectedError: "A3() invoked ReceiveEventAsync while halting.",119 replay: true);120 }121 private class M3 : StateMachine122 {123 [Start]124 [OnEntry(nameof(InitOnEntry))]125 private class Init : State126 {127 }128 private void InitOnEntry() => this.RaiseHaltEvent();129 protected override async Task OnHaltAsync(Event e)130 {131 await this.ReceiveEventAsync(typeof(Event));132 }133 }134 [Fact(Timeout = 5000)]135 public void TestOnHaltAsyncWithReceiveInStateMachine()136 {137 this.TestWithError(r =>138 {139 r.CreateActor(typeof(M3));140 },141 expectedError: "M3() invoked ReceiveEventAsync while halting.",142 replay: true);143 }144 private class Dummy : StateMachine145 {146 [Start]147 [OnEntry(nameof(InitOnEntry))]148 private class Init : State149 {150 }151 private void InitOnEntry() => this.RaiseHaltEvent();152 }153 private class M4Receiver : StateMachine154 {155 [Start]156 [IgnoreEvents(typeof(E))]157 private class Init : State158 {159 }160 }161 private class A4Sender : Actor162 {163 private ActorId Receiver;164 protected override Task OnInitializeAsync(Event initialEvent)165 {166 this.Receiver = (initialEvent as E).Id;167 this.SendEvent(this.Id, HaltEvent.Instance);168 return Task.CompletedTask;169 }170 protected override Task OnHaltAsync(Event e)171 {172 // No-ops but no failure.173 this.SendEvent(this.Receiver, new E());174 this.RandomBoolean();175 this.Assert(true);176 this.CreateActor(typeof(Dummy));177 return Task.CompletedTask;178 }...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!