How to use ConfigureEvent method of Microsoft.Coyote.Actors.BugFinding.Tests.Response class

Best Coyote code snippet using Microsoft.Coyote.Actors.BugFinding.Tests.Response.ConfigureEvent

RaftTests.cs

Source:RaftTests.cs Github

copy

Full Screen

...90 private void ConfiguringOnInit()91 {92 for (int idx = 0; idx < this.NumberOfServers; idx++)93 {94 this.SendEvent(this.Servers[idx], new Server.ConfigureEvent(idx, this.Servers, this.Id));95 }96 this.SendEvent(this.Client, new Client.ConfigureEvent(this.Id));97 this.RaiseEvent(new LocalEvent());98 }99 private class Availability : StateGroup100 {101 [OnEventDoAction(typeof(NotifyLeaderUpdate), nameof(BecomeAvailable))]102 [OnEventDoAction(typeof(ShutDown), nameof(ShuttingDown))]103 [OnEventGotoState(typeof(LocalEvent), typeof(Available))]104 [DeferEvents(typeof(Client.Request))]105 public class Unavailable : State106 {107 }108 [OnEventDoAction(typeof(Client.Request), nameof(SendClientRequestToLeader))]109 [OnEventDoAction(typeof(RedirectRequest), nameof(RedirectClientRequest))]110 [OnEventDoAction(typeof(NotifyLeaderUpdate), nameof(RefreshLeader))]111 [OnEventDoAction(typeof(ShutDown), nameof(ShuttingDown))]112 [OnEventGotoState(typeof(LocalEvent), typeof(Unavailable))]113 public class Available : State114 {115 }116 }117 private void BecomeAvailable(Event e)118 {119 this.UpdateLeader(e as NotifyLeaderUpdate);120 this.RaiseEvent(new LocalEvent());121 }122 private void SendClientRequestToLeader(Event e)123 {124 this.SendEvent(this.Leader, e);125 }126 private void RedirectClientRequest(Event e)127 {128 this.SendEvent(this.Id, (e as RedirectRequest).Request);129 }130 private void RefreshLeader(Event e)131 {132 this.UpdateLeader(e as NotifyLeaderUpdate);133 }134 private void ShuttingDown()135 {136 for (int idx = 0; idx < this.NumberOfServers; idx++)137 {138 this.SendEvent(this.Servers[idx], new Server.ShutDown());139 }140 this.RaiseHaltEvent();141 }142 private void UpdateLeader(NotifyLeaderUpdate request)143 {144 if (this.LeaderTerm < request.Term)145 {146 this.Leader = request.Leader;147 this.LeaderTerm = request.Term;148 }149 }150 }151 /// <summary>152 /// A server in Raft can be one of the following three roles:153 /// follower, candidate or leader.154 /// </summary>155 private class Server : StateMachine156 {157 /// <summary>158 /// Used to configure the server.159 /// </summary>160 public class ConfigureEvent : Event161 {162 public int Id;163 public ActorId[] Servers;164 public ActorId ClusterManager;165 public ConfigureEvent(int id, ActorId[] servers, ActorId manager)166 : base()167 {168 this.Id = id;169 this.Servers = servers;170 this.ClusterManager = manager;171 }172 }173 /// <summary>174 /// Initiated by candidates during elections.175 /// </summary>176 public class VoteRequest : Event177 {178 public int Term; // candidate's term179 public ActorId CandidateId; // candidate requesting vote180 public int LastLogIndex; // index of candidate's last log entry181 public int LastLogTerm; // term of candidate's last log entry182 public VoteRequest(int term, ActorId candidateId, int lastLogIndex, int lastLogTerm)183 : base()184 {185 this.Term = term;186 this.CandidateId = candidateId;187 this.LastLogIndex = lastLogIndex;188 this.LastLogTerm = lastLogTerm;189 }190 }191 /// <summary>192 /// Response to a vote request.193 /// </summary>194 public class VoteResponse : Event195 {196 public int Term; // currentTerm, for candidate to update itself197 public bool VoteGranted; // true means candidate received vote198 public VoteResponse(int term, bool voteGranted)199 : base()200 {201 this.Term = term;202 this.VoteGranted = voteGranted;203 }204 }205 /// <summary>206 /// Initiated by leaders to replicate log entries and207 /// to provide a form of heartbeat.208 /// </summary>209 public class AppendEntriesRequest : Event210 {211 public int Term; // leader's term212 public ActorId LeaderId; // so follower can redirect clients213 public int PrevLogIndex; // index of log entry immediately preceding new ones214 public int PrevLogTerm; // term of PrevLogIndex entry215 public List<Log> Entries; // log entries to store (empty for heartbeat; may send more than one for efficiency)216 public int LeaderCommit; // leader's CommitIndex217 public ActorId ReceiverEndpoint; // client218 public AppendEntriesRequest(int term, ActorId leaderId, int prevLogIndex,219 int prevLogTerm, List<Log> entries, int leaderCommit, ActorId client)220 : base()221 {222 this.Term = term;223 this.LeaderId = leaderId;224 this.PrevLogIndex = prevLogIndex;225 this.PrevLogTerm = prevLogTerm;226 this.Entries = entries;227 this.LeaderCommit = leaderCommit;228 this.ReceiverEndpoint = client;229 }230 }231 /// <summary>232 /// Response to an append entries request.233 /// </summary>234 public class AppendEntriesResponse : Event235 {236 public int Term; // current Term, for leader to update itself237 public bool Success; // true if follower contained entry matching PrevLogIndex and PrevLogTerm238 public ActorId Server;239 public ActorId ReceiverEndpoint; // client240 public AppendEntriesResponse(int term, bool success, ActorId server, ActorId client)241 : base()242 {243 this.Term = term;244 this.Success = success;245 this.Server = server;246 this.ReceiverEndpoint = client;247 }248 }249 // Events for transitioning a server between roles.250 private class BecomeFollower : Event251 {252 }253 private class BecomeCandidate : Event254 {255 }256 private class BecomeLeader : Event257 {258 }259 internal class ShutDown : Event260 {261 }262 /// <summary>263 /// The id of this server.264 /// </summary>265 private int ServerId;266 /// <summary>267 /// The cluster manager id.268 /// </summary>269 private ActorId ClusterManager;270 /// <summary>271 /// The servers.272 /// </summary>273 private ActorId[] Servers;274 /// <summary>275 /// Leader id.276 /// </summary>277 private ActorId LeaderId;278 /// <summary>279 /// The election timer of this server.280 /// </summary>281 private ActorId ElectionTimer;282 /// <summary>283 /// The periodic timer of this server.284 /// </summary>285 private ActorId PeriodicTimer;286 /// <summary>287 /// Latest term server has seen (initialized to 0 on288 /// first boot, increases monotonically).289 /// </summary>290 private int CurrentTerm;291 /// <summary>292 /// Candidate id that received vote in current term (or null if none).293 /// </summary>294 private ActorId VotedFor;295 /// <summary>296 /// Log entries.297 /// </summary>298 private List<Log> Logs;299 /// <summary>300 /// Index of highest log entry known to be committed (initialized301 /// to 0, increases monotonically).302 /// </summary>303 private int CommitIndex;304 /// <summary>305 /// Index of the highest log entry applied (initialized to 0, increases monotonically).306 /// </summary>307 private int LastApplied;308 /// <summary>309 /// For each server, index of the next log entry to send to that310 /// server (initialized to leader last log index + 1).311 /// </summary>312 private Dictionary<ActorId, int> NextIndex;313 /// <summary>314 /// For each server, index of highest log entry known to be replicated315 /// on server (initialized to 0, increases monotonically).316 /// </summary>317 private Dictionary<ActorId, int> MatchIndex;318 /// <summary>319 /// Number of received votes.320 /// </summary>321 private int VotesReceived;322 /// <summary>323 /// The latest client request.324 /// </summary>325 private Client.Request LastClientRequest;326 [Start]327 [OnEntry(nameof(EntryOnInit))]328 [OnEventDoAction(typeof(ConfigureEvent), nameof(SetupEvent))]329 [OnEventGotoState(typeof(BecomeFollower), typeof(Follower))]330 [DeferEvents(typeof(VoteRequest), typeof(AppendEntriesRequest))]331 private class Init : State332 {333 }334 private void EntryOnInit()335 {336 this.CurrentTerm = 0;337 this.LeaderId = null;338 this.VotedFor = null;339 this.Logs = new List<Log>();340 this.CommitIndex = 0;341 this.LastApplied = 0;342 this.NextIndex = new Dictionary<ActorId, int>();343 this.MatchIndex = new Dictionary<ActorId, int>();344 }345 private void SetupEvent(Event e)346 {347 this.ServerId = (e as ConfigureEvent).Id;348 this.Servers = (e as ConfigureEvent).Servers;349 this.ClusterManager = (e as ConfigureEvent).ClusterManager;350 this.ElectionTimer = this.CreateActor(typeof(ElectionTimer));351 this.SendEvent(this.ElectionTimer, new ElectionTimer.ConfigureEvent(this.Id));352 this.PeriodicTimer = this.CreateActor(typeof(PeriodicTimer));353 this.SendEvent(this.PeriodicTimer, new PeriodicTimer.ConfigureEvent(this.Id));354 this.RaiseEvent(new BecomeFollower());355 }356 [OnEntry(nameof(FollowerOnInit))]357 [OnEventDoAction(typeof(Client.Request), nameof(RedirectClientRequest))]358 [OnEventDoAction(typeof(VoteRequest), nameof(VoteAsFollower))]359 [OnEventDoAction(typeof(VoteResponse), nameof(RespondVoteAsFollower))]360 [OnEventDoAction(typeof(AppendEntriesRequest), nameof(AppendEntriesAsFollower))]361 [OnEventDoAction(typeof(AppendEntriesResponse), nameof(RespondAppendEntriesAsFollower))]362 [OnEventDoAction(typeof(ElectionTimer.Timeout), nameof(StartLeaderElection))]363 [OnEventDoAction(typeof(ShutDown), nameof(ShuttingDown))]364 [OnEventGotoState(typeof(BecomeFollower), typeof(Follower))]365 [OnEventGotoState(typeof(BecomeCandidate), typeof(Candidate))]366 [IgnoreEvents(typeof(PeriodicTimer.Timeout))]367 private class Follower : State368 {369 }370 private void FollowerOnInit()371 {372 this.LeaderId = null;373 this.VotesReceived = 0;374 this.SendEvent(this.ElectionTimer, new ElectionTimer.StartTimerEvent());375 }376 private void RedirectClientRequest(Event e)377 {378 if (this.LeaderId != null)379 {380 this.SendEvent(this.LeaderId, e);381 }382 else383 {384 this.SendEvent(this.ClusterManager, new ClusterManager.RedirectRequest(e));385 }386 }387 private void StartLeaderElection()388 {389 this.RaiseEvent(new BecomeCandidate());390 }391 private void VoteAsFollower(Event e)392 {393 var request = e as VoteRequest;394 if (request.Term > this.CurrentTerm)395 {396 this.CurrentTerm = request.Term;397 this.VotedFor = null;398 }399 this.Vote(e as VoteRequest);400 }401 private void RespondVoteAsFollower(Event e)402 {403 var request = e as VoteResponse;404 if (request.Term > this.CurrentTerm)405 {406 this.CurrentTerm = request.Term;407 this.VotedFor = null;408 }409 }410 private void AppendEntriesAsFollower(Event e)411 {412 var request = e as AppendEntriesRequest;413 if (request.Term > this.CurrentTerm)414 {415 this.CurrentTerm = request.Term;416 this.VotedFor = null;417 }418 this.AppendEntries(e as AppendEntriesRequest);419 }420 private void RespondAppendEntriesAsFollower(Event e)421 {422 var request = e as AppendEntriesResponse;423 if (request.Term > this.CurrentTerm)424 {425 this.CurrentTerm = request.Term;426 this.VotedFor = null;427 }428 }429 [OnEntry(nameof(CandidateOnInit))]430 [OnEventDoAction(typeof(Client.Request), nameof(RedirectClientRequest))]431 [OnEventDoAction(typeof(VoteRequest), nameof(VoteAsCandidate))]432 [OnEventDoAction(typeof(VoteResponse), nameof(RespondVoteAsCandidate))]433 [OnEventDoAction(typeof(AppendEntriesRequest), nameof(AppendEntriesAsCandidate))]434 [OnEventDoAction(typeof(AppendEntriesResponse), nameof(RespondAppendEntriesAsCandidate))]435 [OnEventDoAction(typeof(ElectionTimer.Timeout), nameof(StartLeaderElection))]436 [OnEventDoAction(typeof(PeriodicTimer.Timeout), nameof(BroadcastVoteRequests))]437 [OnEventDoAction(typeof(ShutDown), nameof(ShuttingDown))]438 [OnEventGotoState(typeof(BecomeLeader), typeof(Leader))]439 [OnEventGotoState(typeof(BecomeFollower), typeof(Follower))]440 [OnEventGotoState(typeof(BecomeCandidate), typeof(Candidate))]441 private class Candidate : State442 {443 }444 private void CandidateOnInit()445 {446 this.CurrentTerm++;447 this.VotedFor = this.Id;448 this.VotesReceived = 1;449 this.SendEvent(this.ElectionTimer, new ElectionTimer.StartTimerEvent());450 this.BroadcastVoteRequests();451 }452 private void BroadcastVoteRequests()453 {454 // BUG: duplicate votes from same follower455 this.SendEvent(this.PeriodicTimer, new PeriodicTimer.StartTimerEvent());456 for (int idx = 0; idx < this.Servers.Length; idx++)457 {458 if (idx == this.ServerId)459 {460 continue;461 }462 var lastLogIndex = this.Logs.Count;463 var lastLogTerm = this.GetLogTermForIndex(lastLogIndex);464 this.SendEvent(this.Servers[idx], new VoteRequest(this.CurrentTerm, this.Id,465 lastLogIndex, lastLogTerm));466 }467 }468 private void VoteAsCandidate(Event e)469 {470 var request = e as VoteRequest;471 if (request.Term > this.CurrentTerm)472 {473 this.CurrentTerm = request.Term;474 this.VotedFor = null;475 this.Vote(e as VoteRequest);476 this.RaiseEvent(new BecomeFollower());477 }478 else479 {480 this.Vote(e as VoteRequest);481 }482 }483 private void RespondVoteAsCandidate(Event e)484 {485 var request = e as VoteResponse;486 if (request.Term > this.CurrentTerm)487 {488 this.CurrentTerm = request.Term;489 this.VotedFor = null;490 this.RaiseEvent(new BecomeFollower());491 }492 else if (request.Term != this.CurrentTerm)493 {494 return;495 }496 if (request.VoteGranted)497 {498 this.VotesReceived++;499 if (this.VotesReceived >= (this.Servers.Length / 2) + 1)500 {501 this.VotesReceived = 0;502 this.RaiseEvent(new BecomeLeader());503 }504 }505 }506 private void AppendEntriesAsCandidate(Event e)507 {508 var request = e as AppendEntriesRequest;509 if (request.Term > this.CurrentTerm)510 {511 this.CurrentTerm = request.Term;512 this.VotedFor = null;513 this.AppendEntries(e as AppendEntriesRequest);514 this.RaiseEvent(new BecomeFollower());515 }516 else517 {518 this.AppendEntries(e as AppendEntriesRequest);519 }520 }521 private void RespondAppendEntriesAsCandidate(Event e)522 {523 var request = e as AppendEntriesResponse;524 if (request.Term > this.CurrentTerm)525 {526 this.CurrentTerm = request.Term;527 this.VotedFor = null;528 this.RaiseEvent(new BecomeFollower());529 }530 }531 [OnEntry(nameof(LeaderOnInit))]532 [OnEventDoAction(typeof(Client.Request), nameof(ProcessClientRequest))]533 [OnEventDoAction(typeof(VoteRequest), nameof(VoteAsLeader))]534 [OnEventDoAction(typeof(VoteResponse), nameof(RespondVoteAsLeader))]535 [OnEventDoAction(typeof(AppendEntriesRequest), nameof(AppendEntriesAsLeader))]536 [OnEventDoAction(typeof(AppendEntriesResponse), nameof(RespondAppendEntriesAsLeader))]537 [OnEventDoAction(typeof(ShutDown), nameof(ShuttingDown))]538 [OnEventGotoState(typeof(BecomeFollower), typeof(Follower))]539 [IgnoreEvents(typeof(ElectionTimer.Timeout), typeof(PeriodicTimer.Timeout))]540 private class Leader : State541 {542 }543 private void LeaderOnInit()544 {545 this.Monitor<SafetyMonitor>(new SafetyMonitor.NotifyLeaderElected(this.CurrentTerm));546 this.SendEvent(this.ClusterManager, new ClusterManager.NotifyLeaderUpdate(this.Id, this.CurrentTerm));547 var logIndex = this.Logs.Count;548 var logTerm = this.GetLogTermForIndex(logIndex);549 this.NextIndex.Clear();550 this.MatchIndex.Clear();551 for (int idx = 0; idx < this.Servers.Length; idx++)552 {553 if (idx == this.ServerId)554 {555 continue;556 }557 this.NextIndex.Add(this.Servers[idx], logIndex + 1);558 this.MatchIndex.Add(this.Servers[idx], 0);559 }560 for (int idx = 0; idx < this.Servers.Length; idx++)561 {562 if (idx == this.ServerId)563 {564 continue;565 }566 this.SendEvent(this.Servers[idx], new AppendEntriesRequest(this.CurrentTerm, this.Id,567 logIndex, logTerm, new List<Log>(), this.CommitIndex, null));568 }569 }570 private void ProcessClientRequest(Event e)571 {572 this.LastClientRequest = e as Client.Request;573 var log = new Log(this.CurrentTerm, this.LastClientRequest.Command);574 this.Logs.Add(log);575 this.BroadcastLastClientRequest();576 }577 private void BroadcastLastClientRequest()578 {579 var lastLogIndex = this.Logs.Count;580 this.VotesReceived = 1;581 for (int idx = 0; idx < this.Servers.Length; idx++)582 {583 if (idx == this.ServerId)584 {585 continue;586 }587 var server = this.Servers[idx];588 if (lastLogIndex < this.NextIndex[server])589 {590 continue;591 }592 var logs = this.Logs.GetRange(this.NextIndex[server] - 1, this.Logs.Count - (this.NextIndex[server] - 1));593 var prevLogIndex = this.NextIndex[server] - 1;594 var prevLogTerm = this.GetLogTermForIndex(prevLogIndex);595 this.SendEvent(server, new AppendEntriesRequest(this.CurrentTerm, this.Id, prevLogIndex,596 prevLogTerm, logs, this.CommitIndex, this.LastClientRequest.Client));597 }598 }599 private void VoteAsLeader(Event e)600 {601 var request = e as VoteRequest;602 if (request.Term > this.CurrentTerm)603 {604 this.CurrentTerm = request.Term;605 this.VotedFor = null;606 this.RedirectLastClientRequestToClusterManager();607 this.Vote(e as VoteRequest);608 this.RaiseEvent(new BecomeFollower());609 }610 else611 {612 this.Vote(e as VoteRequest);613 }614 }615 private void RespondVoteAsLeader(Event e)616 {617 var request = e as VoteResponse;618 if (request.Term > this.CurrentTerm)619 {620 this.CurrentTerm = request.Term;621 this.VotedFor = null;622 this.RedirectLastClientRequestToClusterManager();623 this.RaiseEvent(new BecomeFollower());624 }625 }626 private void AppendEntriesAsLeader(Event e)627 {628 var request = e as AppendEntriesRequest;629 if (request.Term > this.CurrentTerm)630 {631 this.CurrentTerm = request.Term;632 this.VotedFor = null;633 this.RedirectLastClientRequestToClusterManager();634 this.AppendEntries(e as AppendEntriesRequest);635 this.RaiseEvent(new BecomeFollower());636 }637 }638 private void RespondAppendEntriesAsLeader(Event e)639 {640 var request = e as AppendEntriesResponse;641 if (request.Term > this.CurrentTerm)642 {643 this.CurrentTerm = request.Term;644 this.VotedFor = null;645 this.RedirectLastClientRequestToClusterManager();646 this.RaiseEvent(new BecomeFollower());647 }648 else if (request.Term != this.CurrentTerm)649 {650 return;651 }652 if (request.Success)653 {654 this.NextIndex[request.Server] = this.Logs.Count + 1;655 this.MatchIndex[request.Server] = this.Logs.Count;656 this.VotesReceived++;657 if (request.ReceiverEndpoint != null &&658 this.VotesReceived >= (this.Servers.Length / 2) + 1)659 {660 var commitIndex = this.MatchIndex[request.Server];661 if (commitIndex > this.CommitIndex &&662 this.Logs[commitIndex - 1].Term == this.CurrentTerm)663 {664 this.CommitIndex = commitIndex;665 }666 this.VotesReceived = 0;667 this.LastClientRequest = null;668 this.SendEvent(request.ReceiverEndpoint, new Client.Response());669 }670 }671 else672 {673 if (this.NextIndex[request.Server] > 1)674 {675 this.NextIndex[request.Server] = this.NextIndex[request.Server] - 1;676 }677 var logs = this.Logs.GetRange(this.NextIndex[request.Server] - 1, this.Logs.Count - (this.NextIndex[request.Server] - 1));678 var prevLogIndex = this.NextIndex[request.Server] - 1;679 var prevLogTerm = this.GetLogTermForIndex(prevLogIndex);680 this.SendEvent(request.Server, new AppendEntriesRequest(this.CurrentTerm, this.Id, prevLogIndex,681 prevLogTerm, logs, this.CommitIndex, request.ReceiverEndpoint));682 }683 }684 /// <summary>685 /// Processes the given vote request.686 /// </summary>687 /// <param name="request">VoteRequest.</param>688 private void Vote(VoteRequest request)689 {690 var lastLogIndex = this.Logs.Count;691 var lastLogTerm = this.GetLogTermForIndex(lastLogIndex);692 if (request.Term < this.CurrentTerm ||693 (this.VotedFor != null && this.VotedFor != request.CandidateId) ||694 lastLogIndex > request.LastLogIndex ||695 lastLogTerm > request.LastLogTerm)696 {697 this.SendEvent(request.CandidateId, new VoteResponse(this.CurrentTerm, false));698 }699 else700 {701 this.VotedFor = request.CandidateId;702 this.LeaderId = null;703 this.SendEvent(request.CandidateId, new VoteResponse(this.CurrentTerm, true));704 }705 }706 /// <summary>707 /// Processes the given append entries request.708 /// </summary>709 /// <param name="request">AppendEntriesRequest.</param>710 private void AppendEntries(AppendEntriesRequest request)711 {712 if (request.Term < this.CurrentTerm)713 {714 this.SendEvent(request.LeaderId, new AppendEntriesResponse(this.CurrentTerm, false,715 this.Id, request.ReceiverEndpoint));716 }717 else718 {719 if (request.PrevLogIndex > 0 &&720 (this.Logs.Count < request.PrevLogIndex ||721 this.Logs[request.PrevLogIndex - 1].Term != request.PrevLogTerm))722 {723 this.SendEvent(request.LeaderId, new AppendEntriesResponse(this.CurrentTerm, false, this.Id, request.ReceiverEndpoint));724 }725 else726 {727 if (request.Entries.Count > 0)728 {729 var currentIndex = request.PrevLogIndex + 1;730 foreach (var entry in request.Entries)731 {732 if (this.Logs.Count < currentIndex)733 {734 this.Logs.Add(entry);735 }736 else if (this.Logs[currentIndex - 1].Term != entry.Term)737 {738 this.Logs.RemoveRange(currentIndex - 1, this.Logs.Count - (currentIndex - 1));739 this.Logs.Add(entry);740 }741 currentIndex++;742 }743 }744 if (request.LeaderCommit > this.CommitIndex &&745 this.Logs.Count < request.LeaderCommit)746 {747 this.CommitIndex = this.Logs.Count;748 }749 else if (request.LeaderCommit > this.CommitIndex)750 {751 this.CommitIndex = request.LeaderCommit;752 }753 if (this.CommitIndex > this.LastApplied)754 {755 this.LastApplied++;756 }757 this.LeaderId = request.LeaderId;758 this.SendEvent(request.LeaderId, new AppendEntriesResponse(this.CurrentTerm, true, this.Id, request.ReceiverEndpoint));759 }760 }761 }762 private void RedirectLastClientRequestToClusterManager()763 {764 if (this.LastClientRequest != null)765 {766 this.SendEvent(this.ClusterManager, this.LastClientRequest);767 }768 }769 /// <summary>770 /// Returns the log term for the given log index.771 /// </summary>772 /// <param name="logIndex">Index.</param>773 /// <returns>Term.</returns>774 private int GetLogTermForIndex(int logIndex)775 {776 var logTerm = 0;777 if (logIndex > 0)778 {779 logTerm = this.Logs[logIndex - 1].Term;780 }781 return logTerm;782 }783 private void ShuttingDown()784 {785 this.SendEvent(this.ElectionTimer, HaltEvent.Instance);786 this.SendEvent(this.PeriodicTimer, HaltEvent.Instance);787 this.RaiseHaltEvent();788 }789 }790 private class Client : StateMachine791 {792 /// <summary>793 /// Used to configure the client.794 /// </summary>795 public class ConfigureEvent : Event796 {797 public ActorId Cluster;798 public ConfigureEvent(ActorId cluster)799 : base()800 {801 this.Cluster = cluster;802 }803 }804 /// <summary>805 /// Used for a client request.806 /// </summary>807 internal class Request : Event808 {809 public ActorId Client;810 public int Command;811 public Request(ActorId client, int command)812 : base()813 {814 this.Client = client;815 this.Command = command;816 }817 }818 internal class Response : Event819 {820 }821 private class LocalEvent : Event822 {823 }824 private ActorId Cluster;825 private int LatestCommand;826 private int Counter;827 [Start]828 [OnEntry(nameof(InitOnEntry))]829 [OnEventDoAction(typeof(ConfigureEvent), nameof(SetupEvent))]830 [OnEventGotoState(typeof(LocalEvent), typeof(PumpRequest))]831 private class Init : State832 {833 }834 private void InitOnEntry()835 {836 this.LatestCommand = -1;837 this.Counter = 0;838 }839 private void SetupEvent(Event e)840 {841 this.Cluster = (e as ConfigureEvent).Cluster;842 this.RaiseEvent(new LocalEvent());843 }844 [OnEntry(nameof(PumpRequestOnEntry))]845 [OnEventDoAction(typeof(Response), nameof(ProcessResponse))]846 [OnEventGotoState(typeof(LocalEvent), typeof(PumpRequest))]847 private class PumpRequest : State848 {849 }850 private void PumpRequestOnEntry()851 {852 this.LatestCommand = this.RandomInteger(100);853 this.Counter++;854 this.SendEvent(this.Cluster, new Request(this.Id, this.LatestCommand));855 }856 private void ProcessResponse()857 {858 if (this.Counter is 3)859 {860 this.SendEvent(this.Cluster, new ClusterManager.ShutDown());861 this.RaiseHaltEvent();862 }863 else864 {865 this.RaiseEvent(new LocalEvent());866 }867 }868 }869 private class ElectionTimer : StateMachine870 {871 internal class ConfigureEvent : Event872 {873 public ActorId Target;874 public ConfigureEvent(ActorId id)875 : base()876 {877 this.Target = id;878 }879 }880 internal class StartTimerEvent : Event881 {882 }883 internal class CancelTimer : Event884 {885 }886 internal class Timeout : Event887 {888 }889 private class TickEvent : Event890 {891 }892 private ActorId Target;893 [Start]894 [OnEventDoAction(typeof(ConfigureEvent), nameof(SetupEvent))]895 [OnEventGotoState(typeof(StartTimerEvent), typeof(Active))]896 private class Init : State897 {898 }899 private void SetupEvent(Event e)900 {901 this.Target = (e as ConfigureEvent).Target;902 }903 [OnEntry(nameof(ActiveOnEntry))]904 [OnEventDoAction(typeof(TickEvent), nameof(Tick))]905 [OnEventGotoState(typeof(CancelTimer), typeof(Inactive))]906 [IgnoreEvents(typeof(StartTimerEvent))]907 private class Active : State908 {909 }910 private void ActiveOnEntry()911 {912 this.SendEvent(this.Id, new TickEvent());913 }914 private void Tick()915 {916 if (this.RandomBoolean())917 {918 this.SendEvent(this.Target, new Timeout());919 }920 this.RaiseEvent(new CancelTimer());921 }922 [OnEventGotoState(typeof(StartTimerEvent), typeof(Active))]923 [IgnoreEvents(typeof(CancelTimer), typeof(TickEvent))]924 private class Inactive : State925 {926 }927 }928 private class PeriodicTimer : StateMachine929 {930 internal class ConfigureEvent : Event931 {932 public ActorId Target;933 public ConfigureEvent(ActorId id)934 : base()935 {936 this.Target = id;937 }938 }939 internal class StartTimerEvent : Event940 {941 }942 internal class CancelTimer : Event943 {944 }945 internal class Timeout : Event946 {947 }948 private class TickEvent : Event949 {950 }951 private ActorId Target;952 [Start]953 [OnEventDoAction(typeof(ConfigureEvent), nameof(SetupEvent))]954 [OnEventGotoState(typeof(StartTimerEvent), typeof(Active))]955 private class Init : State956 {957 }958 private void SetupEvent(Event e)959 {960 this.Target = (e as ConfigureEvent).Target;961 }962 [OnEntry(nameof(ActiveOnEntry))]963 [OnEventDoAction(typeof(TickEvent), nameof(Tick))]964 [OnEventGotoState(typeof(CancelTimer), typeof(Inactive))]965 [IgnoreEvents(typeof(StartTimerEvent))]966 private class Active : State967 {968 }969 private void ActiveOnEntry()970 {971 this.SendEvent(this.Id, new TickEvent());972 }973 private void Tick()974 {...

Full Screen

Full Screen

ConfigureEvent

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Threading.Tasks;4using Microsoft.Coyote;5using Microsoft.Coyote.Actors;6using Microsoft.Coyote.Actors.BugFinding.Tests;7using Microsoft.Coyote.BugFinding;8using Microsoft.Coyote.BugFinding.SchedulingStrategies;9using Microsoft.Coyote.BugFinding.Strategies;10using Microsoft.Coyote.TestingServices;11using Microsoft.Coyote.TestingServices.Coverage;12using Microsoft.Coyote.TestingServices.Runtime;13using Microsoft.Coyote.TestingServices.Scheduling;14using Microsoft.Coyote.TestingServices.SchedulingStrategies;15using Microsoft.Coyote.TestingServices.Tracing.Schedule;16using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default;17using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Strategies;18using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Strategies.Default;19using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Strategies.Default.Configurations;20using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Strategies.Default.Configurations.Default;21using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Strategies.Default.Configurations.Default.Strategies;22using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Strategies.Default.Configurations.Default.Strategies.Default;23using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Strategies.Default.Configurations.Default.Strategies.Default.Configurations;24using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Strategies.Default.Configurations.Default.Strategies.Default.Configurations.Default;25using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Strategies.Default.Configurations.Default.Strategies.Default.Configurations.Default.Strategies;26using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Strategies.Default.Configurations.Default.Strategies.Default.Configurations.Default.Strategies.Default;27using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Strategies.Default.Configurations.Default.Strategies.Default.Configurations.Default.Strategies.Default.Configurations;28using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Strategies.Default.Configurations.Default.Strategies.Default.Configurations.Default.Strategies.Default.Configurations.Default;29using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Strategies.Default.Configurations.Default.Strategies.Default.Configurations.Default.Strategies.Default.Configurations.Default.Strategies;30using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Strategies.Default.Configurations.Default.Strategies.Default.Configurations.Default.Strategies.Default.Configurations.Default.Strategies.Default;

Full Screen

Full Screen

ConfigureEvent

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.Coyote.Actors;7using Microsoft.Coyote.Actors.BugFinding.Tests;8{9 {10 protected override void OnEvent(Event e)11 {12 if (e is Request)13 {14 this.ConfigureEvent(typeof(Request), typeof(ConfigureEvent));15 }16 }17 }18}19using System;20using System.Collections.Generic;21using System.Linq;22using System.Text;23using System.Threading.Tasks;24using Microsoft.Coyote.Actors;25using Microsoft.Coyote.Actors.BugFinding.Tests;26{27 {28 }29}30using System;31using System.Collections.Generic;32using System.Linq;33using System.Text;34using System.Threading.Tasks;35using Microsoft.Coyote.Actors;36using Microsoft.Coyote.Actors.BugFinding.Tests;37{38 {39 }40}41using System;42using System.Collections.Generic;43using System.Linq;44using System.Text;45using System.Threading.Tasks;46using Microsoft.Coyote.Actors;47using Microsoft.Coyote.Actors.BugFinding.Tests;48{49 {50 protected override async Task OnInitializeAsync(Event initialEvent)51 {52 var r = this.CreateActor(typeof(Response));53 await this.SendEventAndExecuteAsync(r, new Request());54 }55 }56}57using System;58using System.Collections.Generic;59using System.Linq;60using System.Text;61using System.Threading.Tasks;62using Microsoft.Coyote.Actors;63using Microsoft.Coyote.Actors.BugFinding.Tests;

Full Screen

Full Screen

ConfigureEvent

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using Microsoft.Coyote;4using Microsoft.Coyote.Actors;5using Microsoft.Coyote.Actors.BugFinding.Tests;6using Microsoft.Coyote.Actors.BugFinding.Tests.Response;7using Microsoft.Coyote.Actors.BugFinding.Tests.Response.Test;8using Microsoft.Coyote.Actors.BugFinding.Tests.Response.Test.Events;9using Microsoft.Coyote.Actors.BugFinding.Tests.Response.Test.Machines;10using Microsoft.Coyote.Actors.BugFinding.Tests.Response.Test.Models;11using Microsoft.Coyote.Actors.BugFinding.Tests.Response.Test.Services;12using Microsoft.Coyote.Specifications;13using Microsoft.Coyote.SystematicTesting;14using Microsoft.Coyote.SystematicTesting.Strategies;15using Microsoft.Coyote.Tasks;16using Microsoft.Coyote.TestingServices;17using Microsoft.Coyote.TestingServices.Runtime;18using Microsoft.Coyote.TestingServices.SchedulingStrategies;19using Microsoft.Coyote.TestingServices.Tracing.Schedule;20using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default;21using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Model;22using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Model.Events;23using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Model.Events.Default;24using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Model.Events.Default.Dummy;25using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Model.Events.Default.Exploration;26using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Model.Events.Default.Schedule;27using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Model.Events.Default.Schedule.Execution;28using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Model.Events.Default.Schedule.Execution.Async;29using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Model.Events.Default.Schedule.Execution.Async.Task;30using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Model.Events.Default.Schedule.Execution.Async.Task.ContinueWith;31using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Model.Events.Default.Schedule.Execution.Async.Task.ContinueWith.Continue;32using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Model.Events.Default.Schedule.Execution.Async.Task.ContinueWith.Continue.Continue;33using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.Model.Events.Default.Schedule.Execution.Async.Task.ContinueWith.Continue.Continue.Continue;

Full Screen

Full Screen

ConfigureEvent

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using Microsoft.Coyote;4using Microsoft.Coyote.Actors;5using Microsoft.Coyote.Actors.BugFinding.Tests;6using Microsoft.Coyote.Actors.BugFinding.Tests.Response;7using Microsoft.Coyote.BugFinding;8using Microsoft.Coyote.BugFinding.Replay;9using Microsoft.Coyote.BugFinding.Replay.Tasks;10using Microsoft.Coyote.BugFinding.Replay.Tasks.Local;11using Microsoft.Coyote.BugFinding.Replay.Tasks.Remote;12using Microsoft.Coyote.BugFinding.Replay.Tasks.Remote.Client;13using Microsoft.Coyote.BugFinding.Replay.Tasks.Remote.Server;14using Microsoft.Coyote.BugFinding.Replay.Tasks.Remote.Server.Controllers;15using Microsoft.Coyote.BugFinding.Replay.Tasks.Remote.Server.Services;16using Microsoft.Coyote.BugFinding.Replay.Tasks.Remote.Server.Services.CodeGeneration;17using Microsoft.Coyote.BugFinding.Replay.Tasks.Remote.Server.Services.CodeGeneration.Rewriting;18using Microsoft.Coyote.BugFinding.Replay.Tasks.Remote.Server.Services.CodeGeneration.Rewriting.Rewriters;19using Microsoft.Coyote.BugFinding.Replay.Tasks.Remote.Server.Services.CodeGeneration.Rewriting.Rewriters.CSharpRewriters;20using Microsoft.Coyote.BugFinding.Replay.Tasks.Remote.Server.Services.CodeGeneration.Rewriting.Rewriters.CSharpRewriters.CoyoteRewriters;21using Microsoft.Coyote.BugFinding.Replay.Tasks.Remote.Server.Services.CodeGeneration.Rewriting.Rewriters.CSharpRewriters.CoyoteRewriters.AsyncRewriters;22using Microsoft.Coyote.BugFinding.Replay.Tasks.Remote.Server.Services.CodeGeneration.Rewriting.Rewriters.CSharpRewriters.CoyoteRewriters.StateMachineRewriters;23using Microsoft.Coyote.BugFinding.Replay.Tasks.Remote.Server.Services.CodeGeneration.Rewriting.Rewriters.CSharpRewriters.CoyoteRewriters.TimersRewriters;24using Microsoft.Coyote.BugFinding.Replay.Tasks.Remote.Server.Services.CodeGeneration.Rewriting.Rewriters.CSharpRewriters.CoyoteRewriters.WorkerRewriters;25using Microsoft.Coyote.BugFinding.Replay.Tasks.Remote.Server.Services.CodeGeneration.Rewriting.Rewriters.CSharpRewriters.CoyoteRewriters.YieldRewriters;

Full Screen

Full Screen

ConfigureEvent

Using AI Code Generation

copy

Full Screen

1using System;2using Microsoft.Coyote;3using Microsoft.Coyote.Actors;4using Microsoft.Coyote.Actors.BugFinding.Tests;5using Microsoft.Coyote.Actors.BugFinding.TestingServices;6using Microsoft.Coyote.Actors.BugFinding.TestingServices.Tracing.Schedule;7using Microsoft.Coyote.Actors.BugFinding.TestingServices.Tracing.Schedule.Default;8using Microsoft.Coyote.Actors.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies;9using Microsoft.Coyote.Actors.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.RandomExecution;10using Microsoft.Coyote.Actors.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.RandomExecution.Custom;11using Microsoft.Coyote.Actors.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.RandomExecution.Custom.Strategies;12using Microsoft.Coyote.Actors.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.RandomExecution.Custom.Strategies.StateExploration;13using Microsoft.Coyote.Actors.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.RandomExecution.Custom.Strategies.StateExploration.Custom;14using Microsoft.Coyote.Actors.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.RandomExecution.Custom.Strategies.StateExploration.Custom.Strategies;15using Microsoft.Coyote.Actors.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.RandomExecution.Custom.Strategies.StateExploration.Custom.Strategies.Custom;16using Microsoft.Coyote.Actors.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.RandomExecution.Custom.Strategies.StateExploration.Custom.Strategies.Custom.Strategies;17using Microsoft.Coyote.Actors.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.RandomExecution.Custom.Strategies.StateExploration.Custom.Strategies.Custom.Strategies.Custom;18using Microsoft.Coyote.Actors.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.RandomExecution.Custom.Strategies.StateExploration.Custom.Strategies.Custom.Strategies.Custom.Strategies;19using Microsoft.Coyote.Actors.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.RandomExecution.Custom.Strategies.StateExploration.Custom.Strategies.Custom.Strategies.Custom.Strategies.Custom;20using Microsoft.Coyote.Actors.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.RandomExecution.Custom.Strategies.StateExploration.Custom.Strategies.Custom.Strategies.Custom.Strategies.Custom.Strategies;

Full Screen

Full Screen

ConfigureEvent

Using AI Code Generation

copy

Full Screen

1{2 using System;3 using System.Threading.Tasks;4 using Microsoft.Coyote.Actors;5 using Microsoft.Coyote.Actors.BugFinding.Tests;6 using Xunit;7 using Xunit.Abstractions;8 {9 public ResponseTests(ITestOutputHelper output)10 : base(output)11 {12 }13 {14 public TaskCompletionSource<bool> tcs;15 public E(TaskCompletionSource<bool> tcs)16 {17 this.tcs = tcs;18 }19 }20 {21 public TaskCompletionSource<bool> tcs;22 public M(TaskCompletionSource<bool> tcs)23 {24 this.tcs = tcs;25 }26 }27 {28 public TaskCompletionSource<bool> tcs;29 public N(TaskCompletionSource<bool> tcs)30 {31 this.tcs = tcs;32 }33 }34 {35 public TaskCompletionSource<bool> tcs;36 public ConfiguredEvent(TaskCompletionSource<bool> tcs)37 {38 this.tcs = tcs;39 }40 }41 {42 public TaskCompletionSource<bool> tcs;43 public ConfiguredEventWithPayload(TaskCompletionSource<bool> tcs)44 {45 this.tcs = tcs;46 }47 }48 {49 private TaskCompletionSource<bool> tcs;50 [OnEntry(nameof(InitOnEntry))]51 [OnEventDoAction(typeof(E), nameof(HandleE))]52 [OnEventDoAction(typeof(M), nameof(HandleM))]53 [OnEventDoAction(typeof(N), nameof(HandleN))]54 {55 }56 private void InitOnEntry(Event e)57 {58 this.tcs = (e as E).tcs;59 this.ConfigureEvent<ConfiguredEvent>(new ConfiguredEvent(this.tcs));60 this.ConfigureEvent<ConfiguredEventWithPayload>(new ConfiguredEventWithPayload(this.tcs), 7);61 }62 private void HandleE()63 {64 this.RaiseEvent(new ConfiguredEvent(this.tcs));65 }66 private void HandleM()

Full Screen

Full Screen

ConfigureEvent

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote.Actors;2using Microsoft.Coyote.Actors.BugFinding.Tests;3using Microsoft.Coyote.Actors.BugFinding.Tests.Response;4using Microsoft.Coyote.Actors.BugFinding.Tests.Response.Configuration;5using System;6using System.Collections.Generic;7using System.Linq;8using System.Text;9using System.Threading.Tasks;10using System.Threading.Tasks.Dataflow;11{12 {13 static void Main(string[] args)14 {15 var configuration = Configuration.Create();16 configuration.SchedulingIterations = 1000;17 configuration.SchedulingStrategy = SchedulingStrategy.DFS;18 configuration.MaxFairSchedulingSteps = 1000;19 configuration.MaxUnfairSchedulingSteps = 1000;20 configuration.TestingIterations = 1000;21 configuration.LivenessTemperatureThreshold = 100;22 configuration.RandomSchedulingSeed = 0;23 configuration.EnableDataRaceDetection = true;24 configuration.EnableDeadlockDetection = true;25 configuration.EnableOperationInterleavings = true;26 configuration.EnableActorStateExploration = true;27 configuration.EnableActorTaskInterleavings = true;28 configuration.EnableActorTaskWaitInterleavings = true;29 configuration.EnableActorTaskCancellationInterleavings = true;30 configuration.EnableActorTaskWaitCancellationInterleavings = true;31 configuration.EnableActorTaskWaitAllInterleavings = true;32 configuration.EnableActorTaskWaitAnyInterleavings = true;33 configuration.EnableActorTaskWaitAllCancellationInterleavings = true;

Full Screen

Full Screen

ConfigureEvent

Using AI Code Generation

copy

Full Screen

1{2 static void Main(string[] args)3 {4 var config = Configuration.Create().WithTestingIterations(100);5 var runtime = RuntimeFactory.Create(config);6 runtime.CreateActor(typeof(Actor1));7 runtime.CreateActor(typeof(Actor2));8 runtime.Run();9 }10}11{12 static void Main(string[] args)13 {14 var config = Configuration.Create().WithTestingIterations(100);15 var runtime = RuntimeFactory.Create(config);16 runtime.CreateActor(typeof(Actor1));17 runtime.CreateActor(typeof(Actor2));18 runtime.Run();19 }20}21{22 static void Main(string[] args)23 {24 var config = Configuration.Create().WithTestingIterations(100);25 var runtime = RuntimeFactory.Create(config);26 runtime.CreateActor(typeof(Actor1));27 runtime.CreateActor(typeof(Actor2));28 runtime.Run();29 }30}31{32 static void Main(string[] args)33 {34 var config = Configuration.Create().WithTestingIterations(100);35 var runtime = RuntimeFactory.Create(config);36 runtime.CreateActor(typeof(Actor1));37 runtime.CreateActor(typeof(Actor2));38 runtime.Run();39 }40}41{42 static void Main(string[] args)43 {44 var config = Configuration.Create().WithTestingIterations(100);45 var runtime = RuntimeFactory.Create(config);46 runtime.CreateActor(typeof(Actor1));47 runtime.CreateActor(typeof(Actor2));48 runtime.Run();49 }50}51{52 static void Main(string[] args)53 {54 var config = Configuration.Create().WithTestingIterations(100);55 var runtime = RuntimeFactory.Create(config);56 runtime.CreateActor(typeof(Actor1));57 runtime.CreateActor(typeof(Actor2

Full Screen

Full Screen

ConfigureEvent

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.Coyote;7using Microsoft.Coyote.Actors;8using Microsoft.Coyote.Actors.BugFinding.Tests;9using Microsoft.Coyote.Actors.BugFinding.Tests.Nesting;10using Microsoft.Coyote.Actors.BugFinding.Tests.Nesting.TestEvents;11{12 {13 static void Main(string[] args)14 {15 Task t = Task.Run(() => {16 var runtime = RuntimeFactory.Create();17 runtime.CreateActor(typeof(TestMachine));18 runtime.Run();19 });20 t.Wait();21 }22 }23 {24 [OnEntry(nameof(ConfigureEvent))]25 [OnEventDoAction(typeof(ConfigureEvent), nameof(HandleConfigureEvent))]26 class Init : MachineState { }27 void ConfigureEvent()28 {29 Response.ConfigureEvent(typeof(Event2), typeof(Event1));30 this.Raise(new ConfigureEvent());31 }32 void HandleConfigureEvent()33 {34 this.Raise(new Event2());35 }36 [OnEventDoAction(typeof(Event1), nameof(HandleEvent1))]37 class State1 : MachineState { }38 void HandleEvent1()39 {40 this.Raise(new Halt());41 }42 }43}44at Microsoft.Coyote.SystematicTesting.SchedulingStrategy.GetNextScheduledOperation() in D:\a\1\s\Source\TestingServices\Scheduling\Strategies\SchedulingStrategy.cs:line 14145at Microsoft.Coyote.SystematicTesting.SchedulingStrategy.ScheduleOperation() in D:\a\1\s\Source\TestingServices\Scheduling\Strategies\SchedulingStrategy.cs:line 9646at Microsoft.Coyote.SystematicTesting.SchedulingStrategy.ScheduleNextOperation() in D:\a\1\s\Source\TestingServices\Scheduling\Strategies\SchedulingStrategy.cs:line 7947at Microsoft.Coyote.SystematicTesting.TestScheduler.ScheduleNextOperation() in D:\a\1\s\Source\TestingServices\Scheduling\TestScheduler.cs:line 73

Full Screen

Full Screen

ConfigureEvent

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote;2using Microsoft.Coyote.Actors;3using Microsoft.Coyote.Actors.BugFinding.Tests;4using Microsoft.Coyote.Actors.BugFinding.Tests.RequestResponse;5using Microsoft.Coyote.Specifications;6using System;7using System.Threading.Tasks;8{9 {10 static void Main(string[] args)11 {12 Task.Run(() =>13 {14 Run();15 }).GetAwaiter().GetResult();16 }17 static void Run()18 {19 ActorId actor1 = ActorId.CreateRandom();20 ActorId actor2 = ActorId.CreateRandom();21 Runtime runtime = RuntimeFactory.Create();22 runtime.CreateActor(typeof(Actor1), new Actor1.Config(actor1, actor2));23 runtime.CreateActor(typeof(Actor2), new Actor2.Config(actor2, actor1));24 runtime.SendEvent(actor1, new Request());25 runtime.Wait();26 }27 }28 {29 {30 public ActorId Actor1Id;31 public ActorId Actor2Id;32 public Config(ActorId actor1Id, ActorId actor2Id)33 {34 this.Actor1Id = actor1Id;35 this.Actor2Id = actor2Id;36 }37 }38 private ActorId actor2Id;39 [OnEventDoAction(typeof(Config), nameof(Configure))]40 [OnEventDoAction(typeof(Request), nameof(HandleRequest))]41 {42 }43 private void Configure(Event e)44 {45 var config = e as Config;46 this.actor2Id = config.Actor2Id;47 }48 private void HandleRequest()49 {50 Response.ConfigureEvent(this, this.actor2Id, new Response(), 1000, true, false);51 }52 }

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