Best Coyote code snippet using Microsoft.Coyote.Actors.Coverage.ActorRuntimeLogGraphBuilder.GetOrCreateChild
ActorRuntimeLogGraphBuilder.cs
Source:ActorRuntimeLogGraphBuilder.cs
...188 if (info.Event == eventName)189 {190 // Yay, found it so we can draw the complete link connecting the Sender state to this state!191 string category = string.IsNullOrEmpty(stateName) ? ActorCategory : StateMachineCategory;192 var source = this.GetOrCreateChild(info.Name, info.Type, info.State);193 var target = this.GetOrCreateChild(id?.Name, id?.Type, category, stateName);194 this.GetOrCreateEventLink(source, target, info);195 inbox.RemoveAt(i);196 break;197 }198 }199 }200 }201 }202 /// <inheritdoc/>203 public void OnWaitEvent(ActorId id, string stateName, Type eventType)204 {205 }206 /// <inheritdoc/>207 public void OnWaitEvent(ActorId id, string stateName, params Type[] eventTypes)208 {209 }210 /// <inheritdoc/>211 public void OnStateTransition(ActorId id, string stateName, bool isEntry)212 {213 if (isEntry)214 {215 // record the fact we have entered this state216 this.GetOrCreateChild(id?.Name, id?.Type, stateName);217 }218 }219 /// <inheritdoc/>220 public void OnExecuteAction(ActorId id, string handlingStateName, string currentStateName, string actionName)221 {222 this.LinkTransition(typeof(DoActionEvent), id, handlingStateName, currentStateName, null);223 }224 /// <inheritdoc/>225 public void OnGotoState(ActorId id, string currentStateName, string newStateName)226 {227 this.LinkTransition(typeof(GotoStateEvent), id, currentStateName, currentStateName, newStateName);228 }229 /// <inheritdoc/>230 public void OnPushState(ActorId id, string currentStateName, string newStateName)231 {232 this.LinkTransition(typeof(PushStateEvent), id, currentStateName, currentStateName, newStateName);233 }234 /// <inheritdoc/>235 public void OnPopState(ActorId id, string currentStateName, string restoredStateName)236 {237 if (!string.IsNullOrEmpty(currentStateName))238 {239 this.LinkTransition(typeof(PopStateEvent), id, currentStateName,240 currentStateName, restoredStateName);241 }242 }243 /// <inheritdoc/>244 public void OnHalt(ActorId id, int inboxSize)245 {246 lock (this.Inbox)247 {248 this.HaltedStates.TryGetValue(id, out string stateName);249 var target = this.GetOrCreateChild(id?.Name, id?.Type, "Halt", "Halt");250 // Transition to the Halt state.251 if (!string.IsNullOrEmpty(stateName))252 {253 var source = this.GetOrCreateChild(id?.Name, id?.Type, stateName);254 this.GetOrCreateEventLink(source, target, new EventInfo() { Event = typeof(HaltEvent).FullName });255 }256 }257 }258 private int? GetLinkIndex(GraphNode source, GraphNode target, string id)259 {260 if (this.MergeEventLinks)261 {262 return null;263 }264 return this.Graph.GetUniqueLinkIndex(source, target, id);265 }266 /// <inheritdoc/>267 public void OnDefaultEventHandler(ActorId id, string stateName)268 {269 lock (this.Inbox)270 {271 string resolvedId = this.GetResolveActorId(id?.Name, id?.Type);272 string eventName = typeof(DefaultEvent).FullName;273 this.AddEvent(id.Name, id.Type, id.Name, id.Type, stateName, eventName);274 this.Dequeued[id] = this.PopEvent(resolvedId, eventName);275 }276 }277 /// <inheritdoc/>278 public void OnHandleRaisedEvent(ActorId id, string stateName, Event e)279 {280 lock (this.Inbox)281 {282 // We used the inbox to store raised event, but it should be the first one handled since283 // raised events are highest priority.284 string resolvedId = this.GetResolveActorId(id?.Name, id?.Type);285 lock (this.Inbox)286 {287 if (this.Inbox.TryGetValue(resolvedId, out List<EventInfo> inbox))288 {289 string eventName = e.GetType().FullName;290 for (int i = inbox.Count - 1; i >= 0; i--)291 {292 EventInfo info = inbox[i];293 if (info.Event == eventName)294 {295 this.Dequeued[id] = info;296 break;297 }298 }299 }300 }301 }302 }303 /// <inheritdoc/>304 public void OnPopStateUnhandledEvent(ActorId actorId, string currentStateName, Event e)305 {306 lock (this.Inbox)307 {308 if (e is HaltEvent)309 {310 this.HaltedStates[actorId] = currentStateName;311 }312 }313 }314 /// <inheritdoc/>315 public void OnExceptionThrown(ActorId id, string stateName, string actionName, Exception ex)316 {317 }318 /// <inheritdoc/>319 public void OnExceptionHandled(ActorId id, string stateName, string actionName, Exception ex)320 {321 }322 /// <inheritdoc/>323 public void OnCreateTimer(TimerInfo info)324 {325 // TODO: figure out how to graph timers when we have no "timer id" at this point...326 }327 /// <inheritdoc/>328 public void OnStopTimer(TimerInfo info)329 {330 }331 /// <inheritdoc/>332 public void OnCreateMonitor(string monitorType)333 {334 lock (this.Inbox)335 {336 GraphNode node = this.Graph.GetOrCreateNode(monitorType, monitorType);337 node.Category = MonitorCategory;338 }339 }340 /// <inheritdoc/>341 public void OnMonitorExecuteAction(string monitorType, string stateName, string actionName)342 {343 // Monitors process actions immediately, so this state transition is a result of the only event in the inbox.344 lock (this.Inbox)345 {346 if (this.Inbox.TryGetValue(monitorType, out List<EventInfo> inbox) && inbox.Count > 0)347 {348 var e = inbox[inbox.Count - 1];349 inbox.RemoveAt(inbox.Count - 1);350 // Draw the link connecting the Sender state to this state!351 var source = this.GetOrCreateChild(e.Name, e.Type, e.State);352 var target = this.GetOrCreateChild(monitorType, monitorType, stateName);353 this.GetOrCreateEventLink(source, target, e);354 }355 }356 }357 /// <inheritdoc/>358 public void OnMonitorProcessEvent(string monitorType, string stateName, string senderName, string senderType,359 string senderStateName, Event e)360 {361 lock (this.Inbox)362 {363 string eventName = e.GetType().FullName;364 // Now add a fake event for internal monitor state transition that might now happen as a result of this event,365 // storing the monitor's current state in this event.366 var info = this.AddEvent(monitorType, monitorType, monitorType, monitorType, stateName, eventName);367 // Draw the link connecting the Sender state to this state!368 var source = this.GetOrCreateChild(senderName, senderType, senderStateName);369 var target = this.GetOrCreateChild(monitorType, monitorType, stateName);370 this.GetOrCreateEventLink(source, target, info);371 }372 }373 /// <inheritdoc/>374 public void OnMonitorRaiseEvent(string monitorType, string stateName, Event e)375 {376 // Raising event to self.377 string eventName = e.GetType().FullName;378 this.AddEvent(monitorType, monitorType, monitorType, monitorType, stateName, eventName);379 }380 /// <inheritdoc/>381 public void OnMonitorStateTransition(string monitorType, string stateName, bool isEntry, bool? isInHotState)382 {383 if (isEntry)384 {385 lock (this.Inbox)386 {387 // Monitors process events immediately (and does not call OnDequeue), so this state transition is a result of388 // the fake event we created in OnMonitorProcessEvent.389 if (this.Inbox.TryGetValue(monitorType, out List<EventInfo> inbox) && inbox.Count > 0)390 {391 var info = inbox[inbox.Count - 1];392 inbox.RemoveAt(inbox.Count - 1);393 // draw the link connecting the current state to this new state!394 var source = this.GetOrCreateChild(monitorType, monitorType, info.State);395 var shortStateName = this.GetLabel(monitorType, monitorType, stateName);396 string suffix = string.Empty;397 if (isInHotState.HasValue)398 {399 suffix = (isInHotState is true) ? "[hot]" : "[cold]";400 shortStateName += suffix;401 }402 string label = shortStateName;403 var target = this.GetOrCreateChild(monitorType, monitorType, shortStateName, label);404 // In case this node was already created, we may need to override the label here now that405 // we know this is a hot state. This is because, unfortunately, other OnMonitor* methods406 // do not provide the isInHotState parameter.407 target.Label = label;408 this.GetOrCreateEventLink(source, target, info);409 }410 }411 }412 }413 /// <inheritdoc/>414 public void OnMonitorError(string monitorType, string stateName, bool? isInHotState)415 {416 var source = this.GetOrCreateChild(monitorType, monitorType, stateName);417 source.Category = "Error";418 }419 /// <inheritdoc/>420 public void OnRandom(object result, string callerName, string callerType)421 {422 }423 /// <inheritdoc/>424 public void OnAssertionFailure(string error)425 {426 }427 /// <inheritdoc/>428 public void OnStrategyDescription(string strategyName, string description)429 {430 }431 /// <inheritdoc/>432 public void OnCompleted()433 {434 }435 /// <summary>436 /// Return current graph and reset for next iteration.437 /// </summary>438 /// <param name="reset">Set to true will reset the graph for the next iteration.</param>439 /// <returns>The graph.</returns>440 public Graph SnapshotGraph(bool reset)441 {442 Graph result = this.CurrentGraph;443 if (reset)444 {445 // start fresh.446 this.CurrentGraph = null;447 }448 return result;449 }450 private string GetResolveActorId(string name, string type)451 {452 if (type is null)453 {454 // The sender id can be null if an event is fired from non-actor code.455 return ExternalCodeName;456 }457 if (this.CollapseMachineInstances)458 {459 return type;460 }461 return name;462 }463 private EventInfo AddEvent(string targetName, string targetType, string senderName, string senderType,464 string senderStateName, string eventName)465 {466 string targetId = this.GetResolveActorId(targetName, targetType);467 EventInfo info = null;468 lock (this.Inbox)469 {470 if (!this.Inbox.TryGetValue(targetId, out List<EventInfo> inbox))471 {472 inbox = new List<EventInfo>();473 this.Inbox[targetId] = inbox;474 }475 info = new EventInfo()476 {477 Name = senderName ?? ExternalCodeName,478 Type = senderType ?? ExternalCodeName,479 State = senderStateName,480 Event = eventName481 };482 inbox.Add(info);483 }484 return info;485 }486 private void LinkTransition(Type transitionType, ActorId id, string handlingStateName,487 string currentStateName, string newStateName)488 {489 string name = id.Name;490 string type = id.Type;491 lock (this.Inbox)492 {493 if (this.Dequeued.TryGetValue(id, out EventInfo info))494 {495 // Event was dequeued, but now we know what state is handling this event, so connect the dots...496 if (info.Type != type || info.Name != name || info.State != currentStateName)497 {498 var source = this.GetOrCreateChild(info.Name, info.Type, info.State);499 var target = this.GetOrCreateChild(name, type, currentStateName);500 info.HandlingState = handlingStateName;501 this.GetOrCreateEventLink(source, target, info);502 }503 }504 if (newStateName != null)505 {506 // Then this is a goto or push and we can draw that link also.507 var source = this.GetOrCreateChild(name, type, currentStateName);508 var target = this.GetOrCreateChild(name, type, newStateName);509 if (info is null)510 {511 info = new EventInfo { Event = transitionType.FullName };512 }513 this.GetOrCreateEventLink(source, target, info);514 }515 this.Dequeued.Remove(id);516 }517 }518 private GraphNode GetOrCreateChild(string name, string type, string stateName, string label = null)519 {520 GraphNode child = null;521 lock (this.Inbox)522 {523 this.AddNamespace(type);524 var initalStateName = stateName;525 // make label relative to fully qualified actor id (it's usually a nested class).526 stateName = this.GetLabel(name, type, stateName);527 string id = this.GetResolveActorId(name, type);528 GraphNode parent = this.Graph.GetOrCreateNode(id);529 parent.AddAttribute("Group", "Expanded");530 if (string.IsNullOrEmpty(label))531 {532 label = stateName ?? ExternalStateName;...
GetOrCreateChild
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using Microsoft.Coyote;4using Microsoft.Coyote.Actors;5using Microsoft.Coyote.Actors.Coverage;6using Microsoft.Coyote.Specifications;7using Microsoft.Coyote.Tasks;8{9 {10 public static void Main(string[] args)11 {12 var configuration = Configuration.Create();13 configuration.TraceLevel = 1;14 configuration.MaxSchedulingSteps = 100;15 configuration.MaxFairSchedulingSteps = 100;16 configuration.MaxUnfairSchedulingSteps = 100;17 configuration.SchedulingIterations = 100;18 var runtime = RuntimeFactory.Create(configuration);19 var graphBuilder = new ActorRuntimeLogGraphBuilder(runtime);20 graphBuilder.AddActor(typeof(MachineA));21 graphBuilder.AddActor(typeof(MachineB));22 graphBuilder.AddActor(typeof(MachineC));23 graphBuilder.AddActor(typeof(MachineD));24 graphBuilder.AddActor(typeof(MachineE));25 graphBuilder.AddActor(typeof(MachineF));26 graphBuilder.AddActor(typeof(MachineG));27 graphBuilder.AddActor(typeof(MachineH));28 graphBuilder.AddActor(typeof(MachineI));29 graphBuilder.AddActor(typeof(MachineJ));30 graphBuilder.AddActor(typeof(MachineK));31 graphBuilder.AddActor(typeof(MachineL));32 graphBuilder.AddActor(typeof(MachineM));33 graphBuilder.AddActor(typeof(MachineN));34 graphBuilder.AddActor(typeof(MachineO));35 graphBuilder.AddActor(typeof(MachineP));36 graphBuilder.AddActor(typeof(MachineQ));37 graphBuilder.AddActor(typeof(MachineR));38 graphBuilder.AddActor(typeof(MachineS));39 graphBuilder.AddActor(typeof(MachineT));40 graphBuilder.AddActor(typeof(MachineU));41 graphBuilder.AddActor(typeof(MachineV));42 graphBuilder.AddActor(typeof(MachineW));43 graphBuilder.AddActor(typeof(MachineX));44 graphBuilder.AddActor(typeof(MachineY));45 graphBuilder.AddActor(typeof(MachineZ));46 var graph = graphBuilder.GetOrCreateChild("MachineA", "MachineB");47 graph = graphBuilder.GetOrCreateChild("MachineA", "MachineC");48 graph = graphBuilder.GetOrCreateChild("MachineA", "MachineD");49 graph = graphBuilder.GetOrCreateChild("MachineA", "MachineE");50 graph = graphBuilder.GetOrCreateChild("MachineA", "MachineF");
GetOrCreateChild
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.Coyote.Actors;7using Microsoft.Coyote.Actors.Coverage;8using Microsoft.Coyote.Actors.Coverage.Logging;9using Microsoft.Coyote.Actors.Coverage.Runtime;10using Microsoft.Coyote.Actors.Coverage.Runtime.Logging;11using Microsoft.Coyote.Actors.Coverage.Runtime.Scheduling;12using Microsoft.Coyote.Actors.Coverage.Runtime.Scheduling.Strategies;13using Microsoft.Coyote.Actors.Coverage.Runtime.Scheduling.Strategies.Default;14using Microsoft.Coyote.Actors.Coverage.Runtime.Scheduling.Strategies.FairExploration;15using Microsoft.Coyote.Actors.Coverage.Runtime.Scheduling.Strategies.FairReplay;16using Microsoft.Coyote.Actors.Coverage.Runtime.Scheduling.Strategies.FairReplay.Coverage;17using Microsoft.Coyote.Actors.Coverage.Runtime.Scheduling.Strategies.FairReplay.Coverage.CoverageGraph;18using Microsoft.Coyote.Actors.Coverage.Runtime.Scheduling.Strategies.FairReplay.Coverage.CoverageGraph.CoverageGraphBuilder;19using Microsoft.Coyote.Actors.Coverage.Runtime.Scheduling.Strategies.FairReplay.Coverage.CoverageGraph.CoverageGraphBuilder.CoverageGraphBuilderState;20using Microsoft.Coyote.Actors.Coverage.Runtime.Scheduling.Strategies.FairReplay.Coverage.CoverageGraph.CoverageGraphBuilder.CoverageGraphBuilderState.CoverageGraphBuilderStateFactory;21using Microsoft.Coyote.Actors.Coverage.Runtime.Scheduling.Strategies.FairReplay.Coverage.CoverageGraph.CoverageGraphBuilder.CoverageGraphBuilderState.CoverageGraphBuilderStateFactory.CoverageGraphBuilderStateFactoryImplementation;22using Microsoft.Coyote.Actors.Coverage.Runtime.Scheduling.Strategies.FairReplay.Coverage.CoverageGraph.CoverageGraphBuilder.CoverageGraphBuilderState.CoverageGraphBuilderStateFactory.CoverageGraphBuilderStateFactoryImplementation.CoverageGraphBuilderStateFactoryImplementationState;
GetOrCreateChild
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.Coyote.Actors;7using Microsoft.Coyote.Actors.Coverage;8{9 {10 static void Main(string[] args)11 {12 ActorRuntimeLogGraphBuilder builder = new ActorRuntimeLogGraphBuilder();13 builder.GetOrCreateChild("A");14 builder.GetOrCreateChild("B");15 builder.GetOrCreateChild("C");16 builder.GetOrCreateChild("D");17 builder.GetOrCreateChild("E");18 builder.GetOrCreateChild("F");19 builder.GetOrCreateChild("G");20 builder.GetOrCreateChild("H");21 builder.GetOrCreateChild("I");22 builder.GetOrCreateChild("J");23 builder.GetOrCreateChild("K");24 builder.GetOrCreateChild("L");25 builder.GetOrCreateChild("M");26 builder.GetOrCreateChild("N");27 builder.GetOrCreateChild("O");28 builder.GetOrCreateChild("P");29 builder.GetOrCreateChild("Q");30 builder.GetOrCreateChild("R");31 builder.GetOrCreateChild("S");32 builder.GetOrCreateChild("T");33 builder.GetOrCreateChild("U");34 builder.GetOrCreateChild("V");35 builder.GetOrCreateChild("W");36 builder.GetOrCreateChild("X");37 builder.GetOrCreateChild("Y");38 builder.GetOrCreateChild("Z");39 builder.GetOrCreateChild("AA");40 builder.GetOrCreateChild("AB");41 builder.GetOrCreateChild("AC");42 builder.GetOrCreateChild("AD");43 builder.GetOrCreateChild("AE");44 builder.GetOrCreateChild("AF");45 builder.GetOrCreateChild("AG");46 builder.GetOrCreateChild("AH");47 builder.GetOrCreateChild("AI");48 builder.GetOrCreateChild("AJ");49 builder.GetOrCreateChild("AK");50 builder.GetOrCreateChild("AL");51 builder.GetOrCreateChild("AM");52 builder.GetOrCreateChild("AN");53 builder.GetOrCreateChild("AO");54 builder.GetOrCreateChild("AP");55 builder.GetOrCreateChild("AQ");56 builder.GetOrCreateChild("AR");57 builder.GetOrCreateChild("AS");58 builder.GetOrCreateChild("AT");59 builder.GetOrCreateChild("AU");60 builder.GetOrCreateChild("AV");61 builder.GetOrCreateChild("AW");62 builder.GetOrCreateChild("AX");63 builder.GetOrCreateChild("AY");64 builder.GetOrCreateChild("AZ");
GetOrCreateChild
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.Coyote.Actors;7using Microsoft.Coyote.Actors.Coverage;8{9 {10 static void Main(string[] args)11 {12 var runtime = new ActorRuntime();13 var graphBuilder = new ActorRuntimeLogGraphBuilder(runtime);14 var root = graphBuilder.Root;15 var child = graphBuilder.GetOrCreateChild(root, "Child");16 Console.WriteLine(child.Name);17 }18 }19}
GetOrCreateChild
Using AI Code Generation
1using System;2using Microsoft.Coyote.Actors;3using Microsoft.Coyote.Actors.Coverage;4{5 {6 static void Main(string[] args)7 {8 var runtime = new ActorRuntime();9 var graphBuilder = new ActorRuntimeLogGraphBuilder(runtime);10 var graph = graphBuilder.GetOrCreateChild("1", "2");11 graph = graphBuilder.GetOrCreateChild("2", "3");12 graph = graphBuilder.GetOrCreateChild("3", "4");13 graph = graphBuilder.GetOrCreateChild("4", "5");14 graph = graphBuilder.GetOrCreateChild("5", "6");15 graph = graphBuilder.GetOrCreateChild("6", "7");16 graph = graphBuilder.GetOrCreateChild("7", "8");17 graph = graphBuilder.GetOrCreateChild("8", "9");18 graph = graphBuilder.GetOrCreateChild("9", "10");19 graph = graphBuilder.GetOrCreateChild("10", "11");20 graph = graphBuilder.GetOrCreateChild("11", "12");21 graph = graphBuilder.GetOrCreateChild("12", "13");22 graph = graphBuilder.GetOrCreateChild("13", "14");23 graph = graphBuilder.GetOrCreateChild("14", "15");24 graph = graphBuilder.GetOrCreateChild("15", "16");25 graph = graphBuilder.GetOrCreateChild("16", "17");26 graph = graphBuilder.GetOrCreateChild("17", "18");27 graph = graphBuilder.GetOrCreateChild("18", "19");28 graph = graphBuilder.GetOrCreateChild("19", "20");29 graph = graphBuilder.GetOrCreateChild("20", "21");30 graph = graphBuilder.GetOrCreateChild("21", "22");31 graph = graphBuilder.GetOrCreateChild("22", "23");32 graph = graphBuilder.GetOrCreateChild("23", "24");33 graph = graphBuilder.GetOrCreateChild("24", "25");34 graph = graphBuilder.GetOrCreateChild("25", "26");35 graph = graphBuilder.GetOrCreateChild("26", "27");36 graph = graphBuilder.GetOrCreateChild("27", "28");37 graph = graphBuilder.GetOrCreateChild("28", "29");38 graph = graphBuilder.GetOrCreateChild("29", "30");39 graph = graphBuilder.GetOrCreateChild("30", "31");40 graph = graphBuilder.GetOrCreateChild("31", "
GetOrCreateChild
Using AI Code Generation
1using System;2using System.IO;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7using Microsoft.Coyote.Actors;8{9 {10 static void Main(string[] args)11 {12 var runtime = new ActorRuntime();13 var root = runtime.CreateActor(typeof(Root))
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!