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

Best Coyote code snippet using Microsoft.Coyote.Actors.BugFinding.Tests.ShutDown.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

ReplicatingStorageTests.cs

Source:ReplicatingStorageTests.cs Github

copy

Full Screen

...57 {58 this.NumberOfReplicas = 3;59 this.NumberOfFaults = 1;60 this.AliveNodes = new List<ActorId>();61 this.Monitor<LivenessMonitor>(new LivenessMonitor.ConfigureEvent(this.NumberOfReplicas));62 this.NodeManager = this.CreateActor(typeof(NodeManager));63 this.Client = this.CreateActor(typeof(Client));64 this.RaiseEvent(new LocalEvent());65 }66 [OnEntry(nameof(ConfiguringOnInit))]67 [OnEventGotoState(typeof(LocalEvent), typeof(Active))]68 [DeferEvents(typeof(FailureTimer.Timeout))]69 private class Configuring : State70 {71 }72 private void ConfiguringOnInit()73 {74 this.SendEvent(this.NodeManager, new NodeManager.ConfigureEvent(this.Id, this.NumberOfReplicas));75 this.SendEvent(this.Client, new Client.ConfigureEvent(this.NodeManager));76 this.RaiseEvent(new LocalEvent());77 }78 [OnEventDoAction(typeof(NotifyNode), nameof(UpdateAliveNodes))]79 [OnEventDoAction(typeof(FailureTimer.Timeout), nameof(InjectFault))]80 private class Active : State81 {82 }83 private void UpdateAliveNodes(Event e)84 {85 var node = (e as NotifyNode).Node;86 this.AliveNodes.Add(node);87 if (this.AliveNodes.Count == this.NumberOfReplicas &&88 this.FailureTimer is null)89 {90 this.FailureTimer = this.CreateActor(typeof(FailureTimer));91 this.SendEvent(this.FailureTimer, new FailureTimer.ConfigureEvent(this.Id));92 }93 }94 private void InjectFault()95 {96 if (this.NumberOfFaults is 0 ||97 this.AliveNodes.Count is 0)98 {99 return;100 }101 int nodeId = this.RandomInteger(this.AliveNodes.Count);102 var node = this.AliveNodes[nodeId];103 this.SendEvent(node, new FaultInject());104 this.SendEvent(this.NodeManager, new NodeManager.NotifyFailure(node));105 this.AliveNodes.Remove(node);106 this.NumberOfFaults--;107 if (this.NumberOfFaults is 0)108 {109 this.SendEvent(this.FailureTimer, HaltEvent.Instance);110 }111 }112 }113 private class NodeManager : StateMachine114 {115 public class ConfigureEvent : Event116 {117 public ActorId Environment;118 public int NumberOfReplicas;119 public ConfigureEvent(ActorId env, int numOfReplicas)120 : base()121 {122 this.Environment = env;123 this.NumberOfReplicas = numOfReplicas;124 }125 }126 public class NotifyFailure : Event127 {128 public ActorId Node;129 public NotifyFailure(ActorId node)130 : base()131 {132 this.Node = node;133 }134 }135 internal class ShutDown : Event136 {137 }138 private class LocalEvent : Event139 {140 }141 private ActorId Environment;142 private List<ActorId> StorageNodes;143 private int NumberOfReplicas;144 private Dictionary<int, bool> StorageNodeMap;145 private Dictionary<int, int> DataMap;146 private ActorId RepairTimer;147 [Start]148 [OnEntry(nameof(EntryOnInit))]149 [OnEventDoAction(typeof(ConfigureEvent), nameof(SetupEvent))]150 [OnEventGotoState(typeof(LocalEvent), typeof(Active))]151 [DeferEvents(typeof(Client.Request), typeof(RepairTimer.Timeout))]152 private class Init : State153 {154 }155 private void EntryOnInit()156 {157 this.StorageNodes = new List<ActorId>();158 this.StorageNodeMap = new Dictionary<int, bool>();159 this.DataMap = new Dictionary<int, int>();160 this.RepairTimer = this.CreateActor(typeof(RepairTimer));161 this.SendEvent(this.RepairTimer, new RepairTimer.ConfigureEvent(this.Id));162 }163 private void SetupEvent(Event e)164 {165 this.Environment = (e as ConfigureEvent).Environment;166 this.NumberOfReplicas = (e as ConfigureEvent).NumberOfReplicas;167 for (int idx = 0; idx < this.NumberOfReplicas; idx++)168 {169 this.CreateNewNode();170 }171 this.RaiseEvent(new LocalEvent());172 }173 private void CreateNewNode()174 {175 var idx = this.StorageNodes.Count;176 var node = this.CreateActor(typeof(StorageNode));177 this.StorageNodes.Add(node);178 this.StorageNodeMap.Add(idx, true);179 this.SendEvent(node, new StorageNode.ConfigureEvent(this.Environment, this.Id, idx));180 }181 [OnEventDoAction(typeof(Client.Request), nameof(ProcessClientRequest))]182 [OnEventDoAction(typeof(RepairTimer.Timeout), nameof(RepairNodes))]183 [OnEventDoAction(typeof(StorageNode.SyncReport), nameof(ProcessSyncReport))]184 [OnEventDoAction(typeof(NotifyFailure), nameof(ProcessFailure))]185 private class Active : State186 {187 }188 private void ProcessClientRequest(Event e)189 {190 var command = (e as Client.Request).Command;191 var aliveNodeIds = this.StorageNodeMap.Where(n => n.Value).Select(n => n.Key);192 foreach (var nodeId in aliveNodeIds)193 {194 this.SendEvent(this.StorageNodes[nodeId], new StorageNode.StoreRequest(command));195 }196 }197 private void RepairNodes()198 {199 if (this.DataMap.Count is 0)200 {201 return;202 }203 var latestData = this.DataMap.Values.Max();204 var numOfReplicas = this.DataMap.Count(kvp => kvp.Value == latestData);205 if (numOfReplicas >= this.NumberOfReplicas)206 {207 return;208 }209 foreach (var node in this.DataMap)210 {211 if (node.Value != latestData)212 {213 this.SendEvent(this.StorageNodes[node.Key], new StorageNode.SyncRequest(latestData));214 numOfReplicas++;215 }216 if (numOfReplicas == this.NumberOfReplicas)217 {218 break;219 }220 }221 }222 private void ProcessSyncReport(Event e)223 {224 var nodeId = (e as StorageNode.SyncReport).NodeId;225 var data = (e as StorageNode.SyncReport).Data;226 // LIVENESS BUG: can fail to ever repair again as it thinks there227 // are enough replicas. Enable to introduce a bug fix.228 // if (!this.StorageNodeMap.ContainsKey(nodeId))229 // {230 // return;231 // }232 if (!this.DataMap.ContainsKey(nodeId))233 {234 this.DataMap.Add(nodeId, 0);235 }236 this.DataMap[nodeId] = data;237 }238 private void ProcessFailure(Event e)239 {240 var node = (e as NotifyFailure).Node;241 var nodeId = this.StorageNodes.IndexOf(node);242 this.StorageNodeMap.Remove(nodeId);243 this.DataMap.Remove(nodeId);244 this.CreateNewNode();245 }246 }247 private class StorageNode : StateMachine248 {249 public class ConfigureEvent : Event250 {251 public ActorId Environment;252 public ActorId NodeManager;253 public int Id;254 public ConfigureEvent(ActorId env, ActorId manager, int id)255 : base()256 {257 this.Environment = env;258 this.NodeManager = manager;259 this.Id = id;260 }261 }262 public class StoreRequest : Event263 {264 public int Command;265 public StoreRequest(int cmd)266 : base()267 {268 this.Command = cmd;269 }270 }271 public class SyncReport : Event272 {273 public int NodeId;274 public int Data;275 public SyncReport(int id, int data)276 : base()277 {278 this.NodeId = id;279 this.Data = data;280 }281 }282 public class SyncRequest : Event283 {284 public int Data;285 public SyncRequest(int data)286 : base()287 {288 this.Data = data;289 }290 }291 internal class ShutDown : Event292 {293 }294 private class LocalEvent : Event295 {296 }297 private ActorId Environment;298 private ActorId NodeManager;299 private int NodeId;300 private int Data;301 private ActorId SyncTimer;302 [Start]303 [OnEntry(nameof(EntryOnInit))]304 [OnEventDoAction(typeof(ConfigureEvent), nameof(SetupEvent))]305 [OnEventGotoState(typeof(LocalEvent), typeof(Active))]306 [DeferEvents(typeof(SyncTimer.Timeout))]307 private class Init : State308 {309 }310 private void EntryOnInit()311 {312 this.Data = 0;313 this.SyncTimer = this.CreateActor(typeof(SyncTimer));314 this.SendEvent(this.SyncTimer, new SyncTimer.ConfigureEvent(this.Id));315 }316 private void SetupEvent(Event e)317 {318 this.Environment = (e as ConfigureEvent).Environment;319 this.NodeManager = (e as ConfigureEvent).NodeManager;320 this.NodeId = (e as ConfigureEvent).Id;321 this.Monitor<LivenessMonitor>(new LivenessMonitor.NotifyNodeCreated(this.NodeId));322 this.SendEvent(this.Environment, new Environment.NotifyNode(this.Id));323 this.RaiseEvent(new LocalEvent());324 }325 [OnEventDoAction(typeof(StoreRequest), nameof(Store))]326 [OnEventDoAction(typeof(SyncRequest), nameof(Sync))]327 [OnEventDoAction(typeof(SyncTimer.Timeout), nameof(GenerateSyncReport))]328 [OnEventDoAction(typeof(Environment.FaultInject), nameof(Terminate))]329 private class Active : State330 {331 }332 private void Store(Event e)333 {334 var cmd = (e as StoreRequest).Command;335 this.Data += cmd;336 this.Monitor<LivenessMonitor>(new LivenessMonitor.NotifyNodeUpdate(this.NodeId, this.Data));337 }338 private void Sync(Event e)339 {340 var data = (e as SyncRequest).Data;341 this.Data = data;342 this.Monitor<LivenessMonitor>(new LivenessMonitor.NotifyNodeUpdate(this.NodeId, this.Data));343 }344 private void GenerateSyncReport()345 {346 this.SendEvent(this.NodeManager, new SyncReport(this.NodeId, this.Data));347 }348 private void Terminate()349 {350 this.Monitor<LivenessMonitor>(new LivenessMonitor.NotifyNodeFail(this.NodeId));351 this.SendEvent(this.SyncTimer, HaltEvent.Instance);352 this.RaiseHaltEvent();353 }354 }355 private class FailureTimer : StateMachine356 {357 internal class ConfigureEvent : Event358 {359 public ActorId Target;360 public ConfigureEvent(ActorId id)361 : base()362 {363 this.Target = id;364 }365 }366 internal class StartTimerEvent : Event367 {368 }369 internal class CancelTimer : Event370 {371 }372 internal class Timeout : Event373 {374 }375 private class TickEvent : Event376 {377 }378 private ActorId Target;379 [Start]380 [OnEventDoAction(typeof(ConfigureEvent), nameof(SetupEvent))]381 [OnEventGotoState(typeof(StartTimerEvent), typeof(Active))]382 private class Init : State383 {384 }385 private void SetupEvent(Event e)386 {387 this.Target = (e as ConfigureEvent).Target;388 this.RaiseEvent(new StartTimerEvent());389 }390 [OnEntry(nameof(ActiveOnEntry))]391 [OnEventDoAction(typeof(TickEvent), nameof(Tick))]392 [OnEventGotoState(typeof(CancelTimer), typeof(Inactive))]393 [IgnoreEvents(typeof(StartTimerEvent))]394 private class Active : State395 {396 }397 private void ActiveOnEntry()398 {399 this.SendEvent(this.Id, new TickEvent());400 }401 private void Tick()402 {403 if (this.RandomBoolean())404 {405 this.SendEvent(this.Target, new Timeout());406 }407 this.SendEvent(this.Id, new TickEvent());408 }409 [OnEventGotoState(typeof(StartTimerEvent), typeof(Active))]410 [IgnoreEvents(typeof(CancelTimer), typeof(TickEvent))]411 private class Inactive : State412 {413 }414 }415 private class RepairTimer : StateMachine416 {417 internal class ConfigureEvent : Event418 {419 public ActorId Target;420 public ConfigureEvent(ActorId id)421 : base()422 {423 this.Target = id;424 }425 }426 internal class StartTimerEvent : Event427 {428 }429 internal class CancelTimer : Event430 {431 }432 internal class Timeout : Event433 {434 }435 private class TickEvent : Event436 {437 }438 private ActorId Target;439 [Start]440 [OnEventDoAction(typeof(ConfigureEvent), nameof(SetupEvent))]441 [OnEventGotoState(typeof(StartTimerEvent), typeof(Active))]442 private class Init : State443 {444 }445 private void SetupEvent(Event e)446 {447 this.Target = (e as ConfigureEvent).Target;448 this.RaiseEvent(new StartTimerEvent());449 }450 [OnEntry(nameof(ActiveOnEntry))]451 [OnEventDoAction(typeof(TickEvent), nameof(Tick))]452 [OnEventGotoState(typeof(CancelTimer), typeof(Inactive))]453 [IgnoreEvents(typeof(StartTimerEvent))]454 private class Active : State455 {456 }457 private void ActiveOnEntry()458 {459 this.SendEvent(this.Id, new TickEvent());460 }461 private void Tick()462 {463 if (this.RandomBoolean())464 {465 this.SendEvent(this.Target, new Timeout());466 }467 this.SendEvent(this.Id, new TickEvent());468 }469 [OnEventGotoState(typeof(StartTimerEvent), typeof(Active))]470 [IgnoreEvents(typeof(CancelTimer), typeof(TickEvent))]471 private class Inactive : State472 {473 }474 }475 private class SyncTimer : StateMachine476 {477 internal class ConfigureEvent : Event478 {479 public ActorId Target;480 public ConfigureEvent(ActorId id)481 : base()482 {483 this.Target = id;484 }485 }486 internal class StartTimerEvent : Event487 {488 }489 internal class CancelTimer : Event490 {491 }492 internal class Timeout : Event493 {494 }495 private class TickEvent : Event496 {497 }498 private ActorId Target;499 [Start]500 [OnEventDoAction(typeof(ConfigureEvent), nameof(SetupEvent))]501 [OnEventGotoState(typeof(StartTimerEvent), typeof(Active))]502 private class Init : State503 {504 }505 private void SetupEvent(Event e)506 {507 this.Target = (e as ConfigureEvent).Target;508 this.RaiseEvent(new StartTimerEvent());509 }510 [OnEntry(nameof(ActiveOnEntry))]511 [OnEventDoAction(typeof(TickEvent), nameof(Tick))]512 [OnEventGotoState(typeof(CancelTimer), typeof(Inactive))]513 [IgnoreEvents(typeof(StartTimerEvent))]514 private class Active : State515 {516 }517 private void ActiveOnEntry()518 {519 this.SendEvent(this.Id, new TickEvent());520 }521 private void Tick()522 {523 if (this.RandomBoolean())524 {525 this.SendEvent(this.Target, new Timeout());526 }527 this.SendEvent(this.Id, new TickEvent());528 }529 [OnEventGotoState(typeof(StartTimerEvent), typeof(Active))]530 [IgnoreEvents(typeof(CancelTimer), typeof(TickEvent))]531 private class Inactive : State532 {533 }534 }535 private class Client : StateMachine536 {537 public class ConfigureEvent : Event538 {539 public ActorId NodeManager;540 public ConfigureEvent(ActorId manager)541 : base()542 {543 this.NodeManager = manager;544 }545 }546 internal class Request : Event547 {548 public ActorId Client;549 public int Command;550 public Request(ActorId client, int cmd)551 : base()552 {553 this.Client = client;554 this.Command = cmd;555 }556 }557 private class LocalEvent : Event558 {559 }560 private ActorId NodeManager;561 private int Counter;562 [Start]563 [OnEntry(nameof(InitOnEntry))]564 [OnEventDoAction(typeof(ConfigureEvent), nameof(SetupEvent))]565 [OnEventGotoState(typeof(LocalEvent), typeof(PumpRequest))]566 private class Init : State567 {568 }569 private void InitOnEntry()570 {571 this.Counter = 0;572 }573 private void SetupEvent(Event e)574 {575 this.NodeManager = (e as ConfigureEvent).NodeManager;576 this.RaiseEvent(new LocalEvent());577 }578 [OnEntry(nameof(PumpRequestOnEntry))]579 [OnEventGotoState(typeof(LocalEvent), typeof(PumpRequest))]580 private class PumpRequest : State581 {582 }583 private void PumpRequestOnEntry()584 {585 int command = this.RandomInteger(100) + 1;586 this.Counter++;587 this.SendEvent(this.NodeManager, new Request(this.Id, command));588 if (this.Counter is 1)589 {590 this.RaiseHaltEvent();591 }592 else593 {594 this.RaiseEvent(new LocalEvent());595 }596 }597 }598 private class LivenessMonitor : Monitor599 {600 public class ConfigureEvent : Event601 {602 public int NumberOfReplicas;603 public ConfigureEvent(int numOfReplicas)604 : base()605 {606 this.NumberOfReplicas = numOfReplicas;607 }608 }609 public class NotifyNodeCreated : Event610 {611 public int NodeId;612 public NotifyNodeCreated(int id)613 : base()614 {615 this.NodeId = id;616 }617 }618 public class NotifyNodeFail : Event619 {620 public int NodeId;621 public NotifyNodeFail(int id)622 : base()623 {624 this.NodeId = id;625 }626 }627 public class NotifyNodeUpdate : Event628 {629 public int NodeId;630 public int Data;631 public NotifyNodeUpdate(int id, int data)632 : base()633 {634 this.NodeId = id;635 this.Data = data;636 }637 }638 private class LocalEvent : Event639 {640 }641 private Dictionary<int, int> DataMap;642 private int NumberOfReplicas;643 [Start]644 [OnEntry(nameof(InitOnEntry))]645 [OnEventDoAction(typeof(ConfigureEvent), nameof(SetupEvent))]646 [OnEventGotoState(typeof(LocalEvent), typeof(Repaired))]647 private class Init : State648 {649 }650 private void InitOnEntry()651 {652 this.DataMap = new Dictionary<int, int>();653 }654 private void SetupEvent(Event e)655 {656 this.NumberOfReplicas = (e as ConfigureEvent).NumberOfReplicas;657 this.RaiseEvent(new LocalEvent());658 }659 [Cold]660 [OnEventDoAction(typeof(NotifyNodeCreated), nameof(ProcessNodeCreated))]661 [OnEventDoAction(typeof(NotifyNodeFail), nameof(FailAndCheckRepair))]662 [OnEventDoAction(typeof(NotifyNodeUpdate), nameof(ProcessNodeUpdate))]663 [OnEventGotoState(typeof(LocalEvent), typeof(Repairing))]664 private class Repaired : State665 {666 }667 private void ProcessNodeCreated(Event e)668 {669 var nodeId = (e as NotifyNodeCreated).NodeId;670 this.DataMap.Add(nodeId, 0);...

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;8using Microsoft.Coyote.Actors.Timers;9using Microsoft.Coyote.Actors.BugFinding;10using Microsoft.Coyote.Actors.BugFinding.Tests.ShutDown;11{12 {13 static void Main(string[] args)14 {15 var config = Configuration.Create();16 config.MaxSchedulingSteps = 1000;17 config.MaxFairSchedulingSteps = 1000;18 config.MaxUnfairSchedulingSteps = 1000;19 config.MaxStepsFromBugFinding = 1000;20 config.MaxUnfairSchedulingStepsFromBugFinding = 1000;21 config.MaxFairSchedulingStepsFromBugFinding = 1000;22 config.MaxFairSchedulingStepsFromFairSchedule = 1000;23 config.MaxUnfairSchedulingStepsFromUnfairSchedule = 1000;24 config.MaxFairSchedulingStepsFromUnfairSchedule = 1000;25 config.MaxUnfairSchedulingStepsFromFairSchedule = 1000;26 config.MaxFairSchedulingStepsFromFairSchedule = 1000;27 config.MaxUnfairSchedulingStepsFromUnfairSchedule = 1000;28 config.MaxFairSchedulingStepsFromUnfairSchedule = 1000;29 config.MaxUnfairSchedulingStepsFromFairSchedule = 1000;30 config.MaxFairSchedulingStepsFromFairSchedule = 1000;31 config.MaxUnfairSchedulingStepsFromUnfairSchedule = 1000;32 config.MaxFairSchedulingStepsFromUnfairSchedule = 1000;33 config.MaxUnfairSchedulingStepsFromFairSchedule = 1000;34 config.MaxFairSchedulingStepsFromFairSchedule = 1000;35 config.MaxUnfairSchedulingStepsFromUnfairSchedule = 1000;36 config.MaxFairSchedulingStepsFromUnfairSchedule = 1000;37 config.MaxUnfairSchedulingStepsFromFairSchedule = 1000;38 config.MaxFairSchedulingStepsFromFairSchedule = 1000;39 config.MaxUnfairSchedulingStepsFromUnfairSchedule = 1000;40 config.MaxFairSchedulingStepsFromUnfairSchedule = 1000;

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.TestingServices;7using Microsoft.Coyote.TestingServices.Runtime;8using Microsoft.Coyote.TestingServices.SchedulingStrategies;9using Microsoft.Coyote.TestingServices.Tracing.Schedule;10using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default;11using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.SchedulingStrategies;12{13 {14 static void Main(string[] args)15 {16 var configuration = Configuration.Create();17 configuration.SchedulingStrategy = SchedulingStrategy.DFS;18 configuration.SchedulingIterations = 1000;19 configuration.MaxUnfairSchedulingSteps = 1000;20 configuration.Verbose = 2;21 configuration.SchedulingTrace = SchedulingTrace.Custom;22 configuration.CustomSchedulingStrategy = new CustomSchedulingStrategy();23 configuration.BugFindingIterationBound = 1000;24 configuration.BugFindingIterations = 1000;25 configuration.UseRandomBugFindingStrategy = true;26 configuration.UseRandomTestingStrategy = true;27 configuration.UseSmartBugFinding = true;28 configuration.TestingIterations = 10000;29 configuration.TestingIterationBound = 10000;30 configuration.TestReporters.Add(new Microsoft.Coyote.TestingServices.Reporters.ConsoleReporter());31 var runtime = TestingEngineFactory.Create(configuration, typeof(ShutDown));32 runtime.CreateActor(typeof(ShutDown));33 runtime.Run();34 }35 }36}37using System;38using System.Threading.Tasks;39using Microsoft.Coyote;40using Microsoft.Coyote.Actors;41using Microsoft.Coyote.Actors.BugFinding.Tests;42using Microsoft.Coyote.TestingServices;43using Microsoft.Coyote.TestingServices.Runtime;44using Microsoft.Coyote.TestingServices.SchedulingStrategies;45using Microsoft.Coyote.TestingServices.Tracing.Schedule;46using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default;47using Microsoft.Coyote.TestingServices.Tracing.Schedule.Default.SchedulingStrategies;48{49 {50 static void Main(string[] args)51 {52 var configuration = Configuration.Create();

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.Specifications;4using Microsoft.Coyote.TestingServices;5using Microsoft.Coyote.TestingServices.Runtime;6using Microsoft.Coyote.TestingServices.SchedulingStrategies;7using Microsoft.Coyote.TestingServices.Tracing.Schedule;8using System;9using System.Threading.Tasks;10{11 {12 static void Main(string[] args)13 {14 var configuration = Configuration.Create();15 configuration.SchedulingStrategy = SchedulingStrategy.DFS;16 configuration.MaxSchedulingSteps = 100000;17 configuration.MaxFairSchedulingSteps = 100000;18 configuration.ThrowOnFailure = false;19 configuration.LivenessTemperatureThreshold = 100;20 configuration.DefaultTimeout = 10000;21 configuration.SchedulingIterations = 1000;22 configuration.EnableCycleDetection = false;23 configuration.EnableDataRaceDetection = false;24 configuration.EnableHotStateDetection = false;25 configuration.EnableOperationInterleavings = false;26 configuration.EnableRandomExecution = false;27 configuration.EnableStateGraph = false;28 configuration.EnableActorMonitoring = false;29 configuration.EnableActorStateExploration = false;30 configuration.EnableActorStatePrinting = false;31 configuration.EnableStateGraph = false;32 configuration.EnableVerboseTrace = false;33 configuration.EnableBuggyActorExploration = false;34 configuration.EnableStateGraphScheduling = false;35 configuration.EnableActorStateExploration = false;36 configuration.EnableActorStatePrinting = false;37 configuration.EnableActorStateExploration = false;38 configuration.EnableActorStatePrinting = false;39 configuration.EnableStateGraphScheduling = false;40 configuration.EnableActorStateExploration = false;41 configuration.EnableActorStatePrinting = false;42 configuration.EnableActorStateExploration = false;43 configuration.EnableActorStatePrinting = false;44 configuration.EnableStateGraphScheduling = false;45 configuration.EnableActorStateExploration = false;46 configuration.EnableActorStatePrinting = false;47 configuration.EnableActorStateExploration = false;48 configuration.EnableActorStatePrinting = false;49 configuration.EnableStateGraphScheduling = false;50 configuration.EnableActorStateExploration = false;51 configuration.EnableActorStatePrinting = false;52 configuration.EnableActorStateExploration = false;53 configuration.EnableActorStatePrinting = false;54 configuration.EnableStateGraphScheduling = false;55 configuration.EnableActorStateExploration = false;

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;4using System;5using System.Threading.Tasks;6{7 {8 [OnEventDoAction(typeof(ConfigureEvent), nameof(Configure))]9 {10 }11 void Configure()12 {13 this.SendEvent(this.Id, new HaltEvent());14 }15 }16}17using Microsoft.Coyote.Actors;18using Microsoft.Coyote.Actors.BugFinding.Tests;19using Microsoft.Coyote.Actors.BugFinding;20using System;21using System.Threading.Tasks;22{23 {24 [OnEventDoAction(typeof(ConfigureEvent), nameof(Configure))]25 {26 }27 void Configure()28 {29 this.SendEvent(this.Id, new HaltEvent());30 }31 }32}33using Microsoft.Coyote.Actors;34using Microsoft.Coyote.Actors.BugFinding.Tests;35using Microsoft.Coyote.Actors.BugFinding;36using System;37using System.Threading.Tasks;38{39 {40 [OnEventDoAction(typeof(ConfigureEvent), nameof(Configure))]41 {42 }43 void Configure()44 {45 this.SendEvent(this.Id, new HaltEvent());46 }47 }48}49using Microsoft.Coyote.Actors;50using Microsoft.Coyote.Actors.BugFinding.Tests;51using Microsoft.Coyote.Actors.BugFinding;52using System;53using System.Threading.Tasks;54{55 {

Full Screen

Full Screen

ConfigureEvent

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote.Actors;2using Microsoft.Coyote.BugFinding;3using Microsoft.Coyote.BugFinding.Replay;4using Microsoft.Coyote.BugFinding.Strategies;5using Microsoft.Coyote.BugFinding.TestingServices;6using Microsoft.Coyote.BugFinding.TestingServices.Strategies;7using Microsoft.Coyote.BugFinding.TestingServices.Tracing.Schedule;8using Microsoft.Coyote.BugFinding.TestingServices.Tracing.Schedule.Default;9using Microsoft.Coyote.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies;10using Microsoft.Coyote.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.Exploration;11using Microsoft.Coyote.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.Fuzzing;12using Microsoft.Coyote.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.Replay;13using Microsoft.Coyote.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.ReplayExecution;14using Microsoft.Coyote.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.ReplayExecution.Default;15using Microsoft.Coyote.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.ReplayExecution.Default.Strategies;16using Microsoft.Coyote.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.ReplayExecution.Default.Strategies.Fuzzing;17using Microsoft.Coyote.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.ReplayExecution.Default.Strategies.Replay;18using Microsoft.Coyote.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.ReplayExecution.Default.Strategies.ReplayExecution;19using Microsoft.Coyote.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.ReplayExecution.Default.Strategies.ReplayExecution.Default;20using Microsoft.Coyote.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.ReplayExecution.Default.Strategies.ReplayExecution.Default.Strategies;21using Microsoft.Coyote.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.ReplayExecution.Default.Strategies.ReplayExecution.Default.Strategies.Fuzzing;22using Microsoft.Coyote.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.ReplayExecution.Default.Strategies.ReplayExecution.Default.Strategies.Replay;23using Microsoft.Coyote.BugFinding.TestingServices.Tracing.Schedule.Default.Strategies.ReplayExecution.Default.Strategies.ReplayExecution.Default.Strategies.ReplayExecution;

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.ShutDown;4using System;5using System.Threading.Tasks;6{7 {8 static async Task Main(string[] args)9 {10 var config = Configuration.Create();11 config.MaxSchedulingSteps = 10000;12 config.MaxFairSchedulingSteps = 10000;13 config.RandomSchedulingSeed = 12345;14 config.SchedulingIterations = 100;15 var runtime = RuntimeFactory.Create(config);16 var shutdown = new ShutDown();17 runtime.ConfigureEvent<ShutDownEvent>(shutdown);18 await runtime.CreateActor(typeof(ShutDown), shutdown);19 await runtime.WaitAsync();20 }21 }22}23using Microsoft.Coyote.Actors;24using Microsoft.Coyote.Actors.BugFinding.Tests;25using Microsoft.Coyote.Actors.BugFinding.Tests.ShutDown;26using System;27using System.Threading.Tasks;28{29 {30 static async Task Main(string[] args)31 {32 var config = Configuration.Create();33 config.MaxSchedulingSteps = 10000;34 config.MaxFairSchedulingSteps = 10000;35 config.RandomSchedulingSeed = 12345;36 config.SchedulingIterations = 100;37 var runtime = RuntimeFactory.Create(config);38 runtime.ConfigureEvent<ShutDownEvent>(new ShutDown());39 await runtime.CreateActor(typeof(ShutDown));40 await runtime.WaitAsync();41 }42 }43}44using Microsoft.Coyote.Actors;45using Microsoft.Coyote.Actors.BugFinding.Tests;46using Microsoft.Coyote.Actors.BugFinding.Tests.ShutDown;47using System;48using System.Threading.Tasks;49{50 {51 static async Task Main(string[] args)52 {53 var config = Configuration.Create();54 config.MaxSchedulingSteps = 10000;55 config.MaxFairSchedulingSteps = 10000;56 config.RandomSchedulingSeed = 12345;

Full Screen

Full Screen

ConfigureEvent

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote.Actors.BugFinding.Tests;2using System;3using System.Threading.Tasks;4{5 {6 static void Main(string[] args)7 {8 Console.WriteLine("Hello World!");9 ShutDown.ConfigureEvent(ShutDownEvent.e);10 Console.ReadLine();11 }12 }13}14using Microsoft.Coyote.Actors.BugFinding.Tests;15using System;16using System.Threading.Tasks;17{18 {19 static void Main(string[] args)20 {21 Console.WriteLine("Hello World!");22 ShutDown.ConfigureEvent(ShutDownEvent.e);23 Console.ReadLine();24 }25 }26}

Full Screen

Full Screen

ConfigureEvent

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote.Actors.BugFinding.Tests;2using Microsoft.Coyote.Actors.BugFinding.Tests.ShutDown;3using System;4using System.Threading.Tasks;5{6 {7 static async Task Main(string[] args)8 {9 var config = Configuration.Create();10 config.MaxFairSchedulingSteps = 10000;11 config.MaxUnfairSchedulingSteps = 10000;12 config.MaxStepsFromBugFinding = 10000;13 config.MaxStepsFromBugFindingWithoutProgress = 10000;14 config.RandomSchedulingSeed = 6;15 config.SchedulingIterations = 10;16 config.TestingIterations = 1;17 config.Verbose = 1;18 config.EnableCycleDetection = true;19 config.EnableDataRaceDetection = true;20 config.EnableDoubleWriteDetection = true;21 config.EnableIntegerOverflowDetection = true;22 config.EnableLivelockDetection = true;23 config.EnableLockInversionDetection = true;24 config.EnableLockRecursionDetection = true;25 config.EnableMemorySafetyBugFinding = true;26 config.EnableObjectDisposedExceptionDetection = true;27 config.EnableOperationCanceledExceptionDetection = true;28 config.EnableOutOfMemoryExceptionDetection = true;29 config.EnablePotentialDeadlockDetection = true;30 config.EnableRecursionDepthBoundExceededExceptionDetection = true;31 config.EnableTaskDeadlockDetection = true;32 config.EnableTaskRecursionDepthBoundExceededExceptionDetection = true;33 config.EnableUnobservedTaskExceptionDetection = true;34 config.EnableUnsafeWaitDetection = true;35 config.EnableUncontrolledActorExceptionDetection = true;36 config.EnableUncontrolledTaskExceptionDetection = true;37 config.EnableWaitTaskContinuationBugFinding = true;38 config.EnableWriteAfterDisposeDetection = true;39 config.EnableWriteAfterFreeDetection = true;40 config.EnableWriteAfterReturnDetection = true;41 config.EnableWriteAfterUseDetection = true;42 config.IsFairSchedulingEnabled = true;43 config.IsFairSchedulingRandomized = true;44 config.IsRandomSchedulingEnabled = true;45 config.IsTestingEngineTraceEnabled = true;46 config.IsTestingIterationsRandomized = true;47 config.IsUnfairSchedulingEnabled = true;48 config.IsUnfairSchedulingRandomized = true;49 config.UserAssemblies = "1.dll";

Full Screen

Full Screen

ConfigureEvent

Using AI Code Generation

copy

Full Screen

1ShutDown.ConfigureEvent(typeof(ShutDown), typeof(ShutDownEvent));2ShutDown.ConfigureEvent(typeof(ShutDown), typeof(ShutDownEvent));3ShutDown.ConfigureEvent(typeof(ShutDown), typeof(ShutDownEvent));4ShutDown.ConfigureEvent(typeof(ShutDown), typeof(ShutDownEvent));5ShutDown.ConfigureEvent(typeof(ShutDown), typeof(ShutDownEvent));6ShutDown.ConfigureEvent(typeof(ShutDown), typeof(ShutDownEvent));7ShutDown.ConfigureEvent(typeof(ShutDown), typeof(ShutDownEvent));8ShutDown.ConfigureEvent(typeof(ShutDown), typeof(ShutDownEvent));9ShutDown.ConfigureEvent(typeof(ShutDown), typeof(ShutDownEvent));10ShutDown.ConfigureEvent(typeof(ShutDown), typeof(ShutDownEvent));11ShutDown.ConfigureEvent(typeof(ShutDown), typeof(ShutDownEvent));

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful