How to use SetupEvent class of Microsoft.Coyote.Actors.Tests.StateMachines package

Best Coyote code snippet using Microsoft.Coyote.Actors.Tests.StateMachines.SetupEvent

MemoryLeakTests.cs

Source:MemoryLeakTests.cs Github

copy

Full Screen

...13 public MemoryLeakTests(ITestOutputHelper output)14 : base(output)15 {16 }17 internal class SetupEvent : Event18 {19 public TaskCompletionSource<bool> Tcs = TaskCompletionSource.Create<bool>();20 public List<WeakReference<int[]>> Buffers = new List<WeakReference<int[]>>();21 public bool HaltTest;22 internal void Add(int[] buffer)23 {24 lock (this.Buffers)25 {26 this.Buffers.Add(new WeakReference<int[]>(buffer));27 }28 }29 }30 internal class E : Event31 {32 public ActorId Id;33 public readonly int[] Buffer;34 public E(ActorId id)35 : base()36 {37 this.Id = id;38 this.Buffer = new int[1000];39 }40 }41 private class M : StateMachine42 {43 [Start]44 [OnEntry(nameof(InitOnEntry))]45 private class Init : State46 {47 }48 private async SystemTasks.Task InitOnEntry(Event e)49 {50 var setup = (SetupEvent)e;51 var tcs = setup.Tcs;52 try53 {54 for (int i = 0; i < 100; i++)55 {56 var n = this.CreateActor(typeof(N), e);57 for (int j = 0; j < 100; j++)58 {59 var send = new E(this.Id);60 setup.Add(send.Buffer);61 this.SendEvent(n, send);62 await this.ReceiveEventAsync(typeof(E));63 }64 }65 }66 finally67 {68 tcs.TrySetResult(true);69 }70 tcs.TrySetResult(true);71 }72 }73 private class N : StateMachine74 {75 private int[] Buffer;76 private SetupEvent Setup;77 [Start]78 [OnEntry(nameof(Configure))]79 [OnEventDoAction(typeof(E), nameof(Act))]80 private class Init : State81 {82 }83 private void Configure(Event e)84 {85 this.Setup = (SetupEvent)e;86 this.Buffer = new int[10000];87 this.Buffer[this.Buffer.Length - 1] = 1;88 this.Setup.Add(this.Buffer);89 }90 private void Act(Event e)91 {92 var sender = (e as E).Id;93 var send = new E(this.Id);94 this.Setup.Add(send.Buffer);95 this.SendEvent(sender, new E(this.Id));96 if (this.Setup.HaltTest)97 {98 this.RaiseHaltEvent();99 }100 }101 }102 private static void AssertNoLeaks(SetupEvent e)103 {104 int retries = 10;105 int count = 0;106 do107 {108 GC.Collect(3);109 count = 0;110 foreach (WeakReference<int[]> item in e.Buffers)111 {112 if (item.TryGetTarget(out int[] buffer))113 {114 count++;115 }116 }117 }118 while (retries-- > 0 && count > 1);119 // MacOs really doesn't want to let go of the last one for some reason (perhaps120 // because we are also grabbing references in the above foreach statement).121 Assert.True(count <= 1);122 }123 [Fact(Timeout = 10000)]124 public void TestNoMemoryLeakInEventSending()125 {126 this.Test(async r =>127 {128 var setup = new SetupEvent();129 r.CreateActor(typeof(M), setup);130 await this.WaitAsync(setup.Tcs.Task, 10000);131 r.Stop();132 AssertNoLeaks(setup);133 });134 }135 [Fact(Timeout = 10000)]136 public void TestNoMemoryLeakAfterHalt()137 {138 this.Test(async r =>139 {140 // test that actors don't leak after they've been halted and that141 // subsequent events that are dropped also don't leak.142 var setup = new SetupEvent() { HaltTest = true };143 r.CreateActor(typeof(M), setup);144 await this.WaitAsync(setup.Tcs.Task, 10000);145 r.Stop();146 AssertNoLeaks(setup);147 });148 }149 }150}...

Full Screen

Full Screen

CreationThroughputBenchmark.cs

Source:CreationThroughputBenchmark.cs Github

copy

Full Screen

...11 [MinColumn, MaxColumn, MeanColumn, Q1Column, Q3Column, RankColumn]12 [MarkdownExporter, HtmlExporter, CsvExporter, CsvMeasurementsExporter, RPlotExporter]13 public class CreationThroughputBenchmark14 {15 private class SetupEvent : Event16 {17 public TaskCompletionSource<bool> Tcs;18 public int NumMachines;19 public int Counter;20 public bool DoHalt;21 public SetupEvent(TaskCompletionSource<bool> tcs, int numMachines, bool doHalt)22 {23 this.Tcs = tcs;24 this.NumMachines = numMachines;25 this.Counter = 0;26 this.DoHalt = doHalt;27 }28 }29 private class M : StateMachine30 {31 [Start]32 [OnEntry(nameof(InitOnEntry))]33 private class Init : State34 {35 }36 private void InitOnEntry(Event e)37 {38 var tcs = (e as SetupEvent).Tcs;39 var numMachines = (e as SetupEvent).NumMachines;40 var doHalt = (e as SetupEvent).DoHalt;41 var counter = Interlocked.Increment(ref (e as SetupEvent).Counter);42 if (counter == numMachines)43 {44 tcs.TrySetResult(true);45 }46 if (doHalt)47 {48 this.RaiseHaltEvent();49 }50 }51 }52 private static int NumMachines => 10000;53 private IActorRuntime Runtime;54 [Params(true, false)]55 public bool DoHalt { get; set; }56 [IterationSetup]57 public void IterationSetup()58 {59 if (this.Runtime is null)60 {61 var configuration = Configuration.Create();62 this.Runtime = RuntimeFactory.Create(configuration);63 }64 }65 [Benchmark]66 public async Task MeasureCreationThroughput()67 {68 var tcs = new TaskCompletionSource<bool>();69 var setupEvent = new SetupEvent(tcs, NumMachines, this.DoHalt);70 for (int idx = 0; idx < NumMachines; idx++)71 {72 this.Runtime.CreateActor(typeof(M), null, setupEvent);73 }74 await tcs.Task;75 }76 [IterationCleanup]77 public void IterationClean()78 {79 this.Runtime = null;80 }81 }82}...

Full Screen

Full Screen

SetupEvent

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using Microsoft.Coyote;4using Microsoft.Coyote.Actors;5using Microsoft.Coyote.Actors.Timers;6using Microsoft.Coyote.Specifications;7using Microsoft.Coyote.SystematicTesting;8using Microsoft.Coyote.Tasks;9using Microsoft.Coyote.Tests.Common;10using Microsoft.Coyote.Tests.Common.Actors;11using Microsoft.Coyote.Tests.Common.Actors.Counter;12using Microsoft.Coyote.Tests.Common.Actors.StateMachines;13using Microsoft.Coyote.Tests.Common.Actors.StateMachines.Events;14using Microsoft.Coyote.Tests.Common.Actors.StateMachines.Events.Counter;15using Microsoft.Coyote.Tests.Common.Actors.StateMachines.Events.Machines;16using Microsoft.Coyote.Tests.Common.Actors.StateMachines.Events.Setup;17using Microsoft.Coyote.Tests.Common.Actors.StateMachines.Events.Timers;18using Microsoft.Coyote.Tests.Common.Actors.StateMachines.Events.Tasks;

Full Screen

Full Screen

SetupEvent

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote.Actors;2using Microsoft.Coyote.Actors.Timers;3using Microsoft.Coyote.Actors.TestingServices;4using Microsoft.Coyote.Actors.TestingServices.Runtime;5using Microsoft.Coyote.Actors.TestingServices.Runtime.Loggers;6using Microsoft.Coyote.Actors.TestingServices.Runtime.Loggers.Html;7using Microsoft.Coyote.Actors.TestingServices.Runtime.Loggers.Json;8using Microsoft.Coyote.Actors.TestingServices.Runtime.Loggers.Text;9using Microsoft.Coyote.Actors.TestingServices.Runtime.Loggers.Xml;10using Microsoft.Coyote.Actors.TestingServices.Runtime.SchedulingStrategies;11using Microsoft.Coyote.Actors.TestingServices.Runtime.SchedulingStrategies.DPOR;12using Microsoft.Coyote.Actors.TestingServices.Runtime.SchedulingStrategies.Probabilistic;13using Microsoft.Coyote.Actors.TestingServices.Runtime.SchedulingStrategies.Random;14using Microsoft.Coyote.Actors.TestingServices.Runtime.SchedulingStrategies.RandomExecution;15using Microsoft.Coyote.Actors.TestingServices.Runtime.SchedulingStrategies.SchedulingPolicy;16using Microsoft.Coyote.Actors.TestingServices.Runtime.SchedulingStrategies.StateExploration;17using Microsoft.Coyote.Actors.TestingServices.Runtime.SchedulingStrategies.StateExploration.Strategies;18using Microsoft.Coyote.Actors.TestingServices.Runtime.SchedulingStrategies.StateExploration.Strategies.BoundedExploration;19using Microsoft.Coyote.Actors.TestingServices.Runtime.SchedulingStrategies.StateExploration.Strategies.DPOR;20using Microsoft.Coyote.Actors.TestingServices.Runtime.SchedulingStrategies.StateExploration.Strategies.Probabilistic;21using Microsoft.Coyote.Actors.TestingServices.Runtime.SchedulingStrategies.StateExploration.Strategies.Random;22using Microsoft.Coyote.Actors.TestingServices.Runtime.SchedulingStrategies.StateExploration.Strategies.RandomExecution;23using Microsoft.Coyote.Actors.TestingServices.Runtime.SchedulingStrategies.StateExploration.Strategies.UnfairProbabilistic;24using Microsoft.Coyote.Actors.TestingServices.Runtime.SchedulingStrategies.StateExploration.Strategies.UnfairRandom;25using Microsoft.Coyote.Actors.TestingServices.Runtime.SchedulingStrategies.StateExploration.Strategies.UnfairRandomExecution;26using Microsoft.Coyote.Actors.TestingServices.Runtime.SchedulingStrategies.StateExploration.Strategies.UnfairWeighted;

Full Screen

Full Screen

SetupEvent

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote.Actors;2using Microsoft.Coyote.Actors.TestingServices;3using Microsoft.Coyote.Specifications;4using Microsoft.Coyote.Tasks;5using System;6using System.Collections.Generic;7using System.Text;8using System.Threading.Tasks;9{10 {11 public SetupEvent(int i)12 {13 this.i = i;14 }15 public int i;16 }17 {18 int i;19 [OnEventDoAction(typeof(SetupEvent), nameof(Setup))]20 [OnEventDoAction(typeof(Halt), nameof(Halt))]21 class Init : State { }22 void Setup()23 {24 this.i = (this.ReceivedEvent as SetupEvent).i;25 this.RaiseGotoStateEvent<Running>();26 }27 [OnEntry(nameof(EntryRunning))]28 [OnEventDoAction(typeof(Event), nameof(ActionRunning))]29 [OnEventDoAction(typeof(Halt), nameof(Halt))]30 class Running : State { }31 void EntryRunning()32 {33 this.Assert(this.i == 1);34 }35 void ActionRunning()36 {37 this.Assert(this.i == 1);38 }39 void Halt()40 {41 this.RaiseHaltEvent();42 }43 }44 {45 static void Main(string[] args)46 {47 Configuration configuration = Configuration.Create();48 configuration.LivenessTemperatureThreshold = 500;49 configuration.SchedulingIterations = 10;50 configuration.SchedulingStrategy = SchedulingStrategy.DFS;51 configuration.SchedulingIterations = 100;52 configuration.SchedulingSeed = 0;53 configuration.Verbose = 3;54 configuration.EnableCycleDetection = true;55 configuration.EnableDataRaceDetection = true;56 configuration.EnableHotStateDetection = true;57 configuration.EnableIntegerOverflowDetection = true;58 configuration.EnableLivenessChecking = true;59 configuration.EnableOperationCanceledExceptionSupport = true;60 configuration.EnableObjectDisposedExceptionSupport = true;61 configuration.EnableDeadlockDetection = true;62 configuration.EnableActorGarbageCollection = true;63 configuration.EnableActorMonitoring = true;64 configuration.EnableActorStateTracking = true;65 configuration.EnableFullLogging = true;66 configuration.EnableBuggyActorExceptionTracing = true;67 configuration.EnableActorDebugger = true;68 configuration.EnableActorProfiling = true;

Full Screen

Full Screen

SetupEvent

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote.Actors;2using Microsoft.Coyote.Actors.TestingServices;3using Microsoft.Coyote.Actors.Timers;4using Microsoft.Coyote.Runtime;5using System;6using System.Collections.Generic;7using System.Linq;8using System.Text;9using System.Threading.Tasks;10using System.Threading;11using System.Diagnostics;12using Microsoft.Coyote.Actors.StateMachines;13using System.Collections.Concurrent;14using System.Collections;15{16 {17 public static void Main()18 {19 test3();20 }21 public static void test1()22 {23 var runtime = RuntimeFactory.Create();24 runtime.RegisterMonitor(typeof(Monitor1));25 runtime.CreateActor(typeof(Machine1));26 runtime.CreateActor(typeof(Machine2));27 runtime.Run();28 }29 public static void test2()30 {31 var runtime = RuntimeFactory.Create();32 runtime.RegisterMonitor(typeof(Monitor1));33 runtime.CreateActor(typeof(Machine3));34 runtime.CreateActor(typeof(Machine2));35 runtime.Run();36 }37 public static void test3()38 {39 var runtime = RuntimeFactory.Create();40 runtime.RegisterMonitor(typeof(Monitor1));41 runtime.CreateActor(typeof(Machine1));42 runtime.CreateActor(typeof(Machine2));43 runtime.CreateActor(typeof(Machine3));44 runtime.Run();45 }46 }47 {48 public int Value;49 public SetupEvent(int value)50 {51 this.Value = value;52 }53 }54 {55 [OnEventDoAction(typeof(SetupEvent), nameof(Configure))]56 class Init : State { }57 void Configure()58 {59 this.SendEvent(this.Id, new SetupEvent(1));60 this.SendEvent(this.Id, new SetupEvent(2));61 this.SendEvent(this.Id, new SetupEvent(3));62 this.SendEvent(this.Id, new SetupEvent(4));63 this.SendEvent(this.Id, new SetupEvent(5));64 this.SendEvent(this.Id, new SetupEvent(6));65 this.SendEvent(this.Id, new SetupEvent(7));66 this.SendEvent(this.Id, new SetupEvent(8));67 this.SendEvent(this.Id

Full Screen

Full Screen

SetupEvent

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote.Actors.Tests.StateMachines;2using System;3using System.Threading.Tasks;4{5 {6 static async Task Main(string[] args)7 {8 var setup = new SetupEvent();9 await setup.SendEventAsync();10 }11 }12}

Full Screen

Full Screen

SetupEvent

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote.Actors.Tests.StateMachines;2{3 {4 public int Value;5 public SetupEvent(int value)6 {7 Value = value;8 }9 }10 {11 private int value;12 [OnEntry(nameof(InitOnEntry))]13 [OnEventDoAction(typeof(SetupEvent), nameof(Setup))]14 private class Init : State { }15 private void InitOnEntry()16 {17 this.RaiseEvent(new SetupEvent(5));18 }19 private void Setup(Event e)20 {21 value = (e as SetupEvent).Value;22 }23 }24}25using Microsoft.Coyote.Actors;26{27 {28 public int Value;29 public SetupEvent(int value)30 {31 Value = value;32 }33 }34 {35 private int value;36 [OnEntry(nameof(InitOnEntry))]37 [OnEventDoAction(typeof(SetupEvent), nameof(Setup))]38 private class Init : State { }39 private void InitOnEntry()40 {41 this.RaiseEvent(new SetupEvent(5));42 }43 private void Setup(SetupEvent e)44 {45 value = e.Value;46 }47 }48}

Full Screen

Full Screen

SetupEvent

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote.Actors.Tests.StateMachines;2using Microsoft.Coyote.Actors;3{4 {5 public Actor1(ActorId id) : base(id)6 {7 }8 [OnEventDoAction(typeof(SetupEvent), nameof(Setup))]9 {10 }11 private void Setup(Event e)12 {13 var setupEvent = e as SetupEvent;14 this.SendEvent(setupEvent.ActorId, new Event());15 }16 }17}18using Microsoft.Coyote.Actors.Tests;19using Microsoft.Coyote.Actors;20{21 {22 public Actor2(ActorId id) : base(id)23 {24 }25 [OnEventDoAction(typeof(SetupEvent), nameof(Setup))]26 {27 }28 private void Setup(Event e)29 {30 var setupEvent = e as SetupEvent;31 this.SendEvent(setupEvent.ActorId, new Event());32 }33 }34}35using Microsoft.Coyote.Actors;36using Microsoft.Coyote.Actors.Tests;37{38 {39 public Actor3(ActorId id) : base(id)40 {41 }42 [OnEventDoAction(typeof(SetupEvent), nameof(Setup))]43 {44 }45 private void Setup(Event e)46 {47 var setupEvent = e as SetupEvent;48 this.SendEvent(setupEvent.ActorId, new Event());49 }50 }51}52using Microsoft.Coyote.Actors;53using Microsoft.Coyote.Actors.Tests;54{55 {56 public Actor4(ActorId id) : base(id)57 {58 }59 [OnEventDoAction(typeof(SetupEvent), nameof(Setup))]

Full Screen

Full Screen

SetupEvent

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote.Actors.Tests.StateMachines;2using System;3using System.Threading.Tasks;4{5 {6 public static async Task Main()7 {8 var setup = new SetupEvent();9 var machine = new MyMachine();10 var runtime = new CoyoteRuntime();11 await runtime.CreateActor(typeof(MyMachine), setup);12 }13 }14}15C:\Users\user\AppData\Local\Temp\1.cs(17,37): error CS0246: The type or namespace name 'CoyoteRuntime' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\user\AppData\Local\Temp\1.csproj]16var runtime = new CoyoteRuntime(typeof(MyMachine));17C:\Users\user\AppData\Local\Temp\1.cs(17,37): error CS0246: The type or namespace name 'CoyoteRuntime' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\user\AppData\Local\Temp\1.csproj]18var runtime = new CoyoteRuntime(typeof(MyMachine));19C:\Users\user\AppData\Local\Temp\1.cs(17,37): error CS0246: The type or namespace name 'CoyoteRuntime' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\user\AppData\Local\Temp\1.csproj]20var runtime = new CoyoteRuntime(typeof(MyMachine));21C:\Users\user\AppData\Local\Temp\1.cs(17,37): error CS0246: The type or namespace name 'CoyoteRuntime' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\user\AppData\Local\Temp\1.csproj]22var runtime = new CoyoteRuntime(typeof(MyMachine));

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Coyote automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful