How to use OnActorEventHandlerCompleted method of Microsoft.Coyote.Actors.ActorExecutionContext class

Best Coyote code snippet using Microsoft.Coyote.Actors.ActorExecutionContext.OnActorEventHandlerCompleted

ActorExecutionContext.cs

Source:ActorExecutionContext.cs Github

copy

Full Screen

...360 if (actor.IsHalted)361 {362 this.ActorMap.TryRemove(actor.Id, out Actor _);363 }364 this.OnActorEventHandlerCompleted(actor.Id);365 }366 }367 /// <summary>368 /// Invoked when the event handler of the specified actor starts.369 /// </summary>370 protected void OnActorEventHandlerStarted(ActorId actorId)371 {372 if (this.Runtime.SchedulingPolicy != SchedulingPolicy.None)373 {374 lock (this.QuiescenceSyncObject)375 {376 this.EnabledActors.Add(actorId);377 }378 }379 }380 /// <summary>381 /// Invoked when the event handler of the specified actor completes.382 /// </summary>383 protected void OnActorEventHandlerCompleted(ActorId actorId)384 {385 if (this.Runtime.SchedulingPolicy != SchedulingPolicy.None)386 {387 lock (this.QuiescenceSyncObject)388 {389 this.EnabledActors.Remove(actorId);390 if (this.IsActorQuiescenceAwaited && this.EnabledActors.Count is 0)391 {392 this.QuiescenceCompletionSource.TrySetResult(true);393 }394 }395 }396 }397 /// <summary>398 /// Creates a new timer that sends a <see cref="TimerElapsedEvent"/> to its owner actor.399 /// </summary>400 internal virtual IActorTimer CreateActorTimer(TimerInfo info, Actor owner) => new ActorTimer(info, owner);401 /// <inheritdoc/>402 public virtual EventGroup GetCurrentEventGroup(ActorId currentActorId)403 {404 Actor actor = this.GetActorWithId<Actor>(currentActorId);405 return actor?.CurrentEventGroup;406 }407 /// <summary>408 /// Gets the actor of type <typeparamref name="TActor"/> with the specified id,409 /// or null if no such actor exists.410 /// </summary>411 private TActor GetActorWithId<TActor>(ActorId id)412 where TActor : Actor =>413 id != null && this.ActorMap.TryGetValue(id, out Actor value) &&414 value is TActor actor ? actor : null;415 /// <summary>416 /// Returns the next available unique operation id.417 /// </summary>418 /// <returns>Value representing the next available unique operation id.</returns>419 private ulong GetNextOperationId() => this.Runtime.GetNextOperationId();420 /// <inheritdoc/>421 public bool RandomBoolean() => this.GetNondeterministicBooleanChoice(null, null);422 /// <summary>423 /// Returns a controlled nondeterministic boolean choice.424 /// </summary>425 internal virtual bool GetNondeterministicBooleanChoice(string callerName, string callerType) =>426 this.Runtime.GetNextNondeterministicBooleanChoice(callerName, callerType);427 /// <inheritdoc/>428 public int RandomInteger(int maxValue) => this.GetNondeterministicIntegerChoice(maxValue, null, null);429 /// <summary>430 /// Returns a controlled nondeterministic integer choice.431 /// </summary>432 internal virtual int GetNondeterministicIntegerChoice(int maxValue, string callerName, string callerType) =>433 this.Runtime.GetNextNondeterministicIntegerChoice(maxValue, callerName, callerType);434 /// <summary>435 /// Logs that the specified actor invoked an action.436 /// </summary>437 internal virtual void LogInvokedAction(Actor actor, MethodInfo action, string handlingStateName, string currentStateName)438 {439 if (this.Configuration.IsVerbose)440 {441 this.LogWriter.LogExecuteAction(actor.Id, handlingStateName, currentStateName, action.Name);442 }443 }444 /// <summary>445 /// Logs that the specified actor enqueued an <see cref="Event"/>.446 /// </summary>447 internal virtual void LogEnqueuedEvent(Actor actor, Event e, EventGroup eventGroup, EventInfo eventInfo)448 {449 if (this.Configuration.IsVerbose)450 {451 this.LogWriter.LogEnqueueEvent(actor.Id, e);452 }453 }454 /// <summary>455 /// Logs that the specified actor dequeued an <see cref="Event"/>.456 /// </summary>457 internal virtual void LogDequeuedEvent(Actor actor, Event e, EventInfo eventInfo, bool isFreshDequeue)458 {459 if (this.Configuration.IsVerbose)460 {461 string stateName = actor is StateMachine stateMachine ? stateMachine.CurrentStateName : default;462 this.LogWriter.LogDequeueEvent(actor.Id, stateName, e);463 }464 }465 /// <summary>466 /// Logs that the specified actor dequeued the default <see cref="Event"/>.467 /// </summary>468 [MethodImpl(MethodImplOptions.AggressiveInlining)]469 internal virtual void LogDefaultEventDequeued(Actor actor)470 {471 }472 /// <summary>473 /// Logs that the specified actor raised an <see cref="Event"/>.474 /// </summary>475 internal virtual void LogRaisedEvent(Actor actor, Event e, EventGroup eventGroup, EventInfo eventInfo)476 {477 if (this.Configuration.IsVerbose)478 {479 string stateName = actor is StateMachine stateMachine ? stateMachine.CurrentStateName : default;480 this.LogWriter.LogRaiseEvent(actor.Id, stateName, e);481 }482 }483 /// <summary>484 /// Logs that the specified actor is handling a raised <see cref="Event"/>.485 /// </summary>486 internal virtual void LogHandleRaisedEvent(Actor actor, Event e)487 {488 if (this.Configuration.IsVerbose)489 {490 string stateName = actor is StateMachine stateMachine ? stateMachine.CurrentStateName : default;491 this.LogWriter.LogHandleRaisedEvent(actor.Id, stateName, e);492 }493 }494 /// <summary>495 /// Logs that the specified actor is handling a raised <see cref="HaltEvent"/>.496 /// </summary>497 internal virtual void LogHandleHaltEvent(Actor actor, int inboxSize)498 {499 if (this.Configuration.IsVerbose)500 {501 this.LogWriter.LogHalt(actor.Id, inboxSize);502 }503 }504 /// <summary>505 /// Logs that the specified actor called <see cref="Actor.ReceiveEventAsync(Type[])"/>506 /// or one of its overloaded methods.507 /// </summary>508 [MethodImpl(MethodImplOptions.AggressiveInlining)]509 internal virtual void LogReceiveCalled(Actor actor)510 {511 }512 /// <summary>513 /// Logs that the specified actor enqueued an event that it was waiting to receive.514 /// </summary>515 internal virtual void LogReceivedEvent(Actor actor, Event e, EventInfo eventInfo)516 {517 if (this.Configuration.IsVerbose)518 {519 string stateName = actor is StateMachine stateMachine ? stateMachine.CurrentStateName : default;520 this.LogWriter.LogReceiveEvent(actor.Id, stateName, e, wasBlocked: true);521 }522 }523 /// <summary>524 /// Logs that the specified actor received an event without waiting because the event525 /// was already in the inbox when the actor invoked the receive statement.526 /// </summary>527 internal virtual void LogReceivedEventWithoutWaiting(Actor actor, Event e, EventInfo eventInfo)528 {529 if (this.Configuration.IsVerbose)530 {531 string stateName = actor is StateMachine stateMachine ? stateMachine.CurrentStateName : default;532 this.LogWriter.LogReceiveEvent(actor.Id, stateName, e, wasBlocked: false);533 }534 }535 /// <summary>536 /// Logs that the specified actor is waiting to receive an event of one of the specified types.537 /// </summary>538 internal virtual void LogWaitEvent(Actor actor, IEnumerable<Type> eventTypes)539 {540 if (this.Configuration.IsVerbose)541 {542 string stateName = actor is StateMachine stateMachine ? stateMachine.CurrentStateName : default;543 var eventWaitTypesArray = eventTypes.ToArray();544 if (eventWaitTypesArray.Length is 1)545 {546 this.LogWriter.LogWaitEvent(actor.Id, stateName, eventWaitTypesArray[0]);547 }548 else549 {550 this.LogWriter.LogWaitEvent(actor.Id, stateName, eventWaitTypesArray);551 }552 }553 }554 /// <summary>555 /// Logs that the event handler of the specified actor terminated.556 /// </summary>557 internal virtual void LogEventHandlerTerminated(Actor actor, DequeueStatus dequeueStatus)558 {559 if (this.Configuration.IsVerbose)560 {561 string stateName = actor is StateMachine stateMachine ? stateMachine.CurrentStateName : default;562 this.LogWriter.LogEventHandlerTerminated(actor.Id, stateName, dequeueStatus);563 }564 }565 /// <summary>566 /// Logs that the specified state machine entered a state.567 /// </summary>568 internal virtual void LogEnteredState(StateMachine stateMachine)569 {570 if (this.Configuration.IsVerbose)571 {572 this.LogWriter.LogStateTransition(stateMachine.Id, stateMachine.CurrentStateName, isEntry: true);573 }574 }575 /// <summary>576 /// Logs that the specified state machine exited a state.577 /// </summary>578 internal virtual void LogExitedState(StateMachine stateMachine)579 {580 if (this.Configuration.IsVerbose)581 {582 this.LogWriter.LogStateTransition(stateMachine.Id, stateMachine.CurrentStateName, isEntry: false);583 }584 }585 /// <summary>586 /// Logs that the specified state machine invoked pop.587 /// </summary>588 [MethodImpl(MethodImplOptions.AggressiveInlining)]589 internal virtual void LogPopState(StateMachine stateMachine)590 {591 }592 /// <summary>593 /// Logs that the specified state machine invoked an action.594 /// </summary>595 internal virtual void LogInvokedOnEntryAction(StateMachine stateMachine, MethodInfo action)596 {597 if (this.Configuration.IsVerbose)598 {599 this.LogWriter.LogExecuteAction(stateMachine.Id, stateMachine.CurrentStateName,600 stateMachine.CurrentStateName, action.Name);601 }602 }603 /// <summary>604 /// Logs that the specified state machine invoked an action.605 /// </summary>606 internal virtual void LogInvokedOnExitAction(StateMachine stateMachine, MethodInfo action)607 {608 if (this.Configuration.IsVerbose)609 {610 this.LogWriter.LogExecuteAction(stateMachine.Id, stateMachine.CurrentStateName,611 stateMachine.CurrentStateName, action.Name);612 }613 }614 /// <summary>615 /// Builds the coverage graph information, if any. This information is only available616 /// when <see cref="Configuration.IsActivityCoverageReported"/> is enabled.617 /// </summary>618 internal CoverageInfo BuildCoverageInfo()619 {620 var result = this.CoverageInfo;621 if (result != null)622 {623 var builder = this.LogWriter.GetLogsOfType<ActorRuntimeLogGraphBuilder>()624 .FirstOrDefault(builder => builder.CollapseInstances);625 if (builder != null)626 {627 result.CoverageGraph = builder.SnapshotGraph(false);628 }629 var eventCoverage = this.LogWriter.GetLogsOfType<ActorRuntimeLogEventCoverage>().FirstOrDefault();630 if (eventCoverage != null)631 {632 result.EventInfo = eventCoverage.EventCoverage;633 }634 }635 return result;636 }637 /// <summary>638 /// Returns the DGML graph of the current execution, if there is any.639 /// </summary>640 internal Graph GetExecutionGraph()641 {642 Graph result = null;643 var builder = this.LogWriter.GetLogsOfType<ActorRuntimeLogGraphBuilder>()644 .FirstOrDefault(builder => !builder.CollapseInstances);645 if (builder != null)646 {647 result = builder.SnapshotGraph(true);648 }649 return result;650 }651 /// <summary>652 /// Returns the program counter of the specified actor.653 /// </summary>654 [MethodImpl(MethodImplOptions.AggressiveInlining)]655 internal virtual int GetActorProgramCounter(ActorId actorId) => 0;656 /// <inheritdoc/>657 public void RegisterMonitor<T>()658 where T : Monitor =>659 this.Runtime.RegisterMonitor<T>();660 /// <inheritdoc/>661 public void Monitor<T>(Event e)662 where T : Monitor =>663 this.Runtime.Monitor<T>(e);664 /// <summary>665 /// Invokes the specified <see cref="Specifications.Monitor"/> with the specified <see cref="Event"/>.666 /// </summary>667 internal void InvokeMonitor(Type type, Event e, string senderName, string senderType, string senderStateName) =>668 this.Runtime.InvokeMonitor(type, e, senderName, senderType, senderStateName);669 /// <inheritdoc/>670 [MethodImpl(MethodImplOptions.AggressiveInlining)]671 public void Assert(bool predicate) => this.Runtime.Assert(predicate);672 /// <inheritdoc/>673 [MethodImpl(MethodImplOptions.AggressiveInlining)]674 public void Assert(bool predicate, string s, object arg0) => this.Runtime.Assert(predicate, s, arg0);675 /// <inheritdoc/>676 [MethodImpl(MethodImplOptions.AggressiveInlining)]677 public void Assert(bool predicate, string s, object arg0, object arg1) => this.Runtime.Assert(predicate, s, arg0, arg1);678 /// <inheritdoc/>679 [MethodImpl(MethodImplOptions.AggressiveInlining)]680 public void Assert(bool predicate, string s, object arg0, object arg1, object arg2) =>681 this.Runtime.Assert(predicate, s, arg0, arg1, arg2);682 /// <inheritdoc/>683 [MethodImpl(MethodImplOptions.AggressiveInlining)]684 public void Assert(bool predicate, string s, params object[] args) => this.Runtime.Assert(predicate, s, args);685 /// <summary>686 /// Asserts that the actor calling an actor method is also the actor that is currently executing.687 /// </summary>688 [MethodImpl(MethodImplOptions.AggressiveInlining)]689 internal virtual void AssertExpectedCallerActor(Actor caller, string calledAPI)690 {691 }692 /// <summary>693 /// Raises the <see cref="OnFailure"/> event with the specified <see cref="Exception"/>.694 /// </summary>695 internal void RaiseOnFailureEvent(Exception exception) => this.Runtime.RaiseOnFailureEvent(exception);696 /// <summary>697 /// Handle the specified dropped <see cref="Event"/>.698 /// </summary>699 internal void HandleDroppedEvent(Event e, ActorId id) => this.OnEventDropped?.Invoke(e, id);700 /// <summary>701 /// Throws an <see cref="AssertionFailureException"/> exception containing the specified exception.702 /// </summary>703#if !DEBUG704 [DebuggerHidden]705#endif706 internal void WrapAndThrowException(Exception exception, string s, params object[] args) =>707 this.Runtime.WrapAndThrowException(exception, s, args);708 /// <inheritdoc/>709 [Obsolete("Please set the Logger property directory instead of calling this method.")]710 public TextWriter SetLogger(TextWriter logger)711 {712 var result = this.LogWriter.SetLogger(new TextWriterLogger(logger));713 if (result != null)714 {715 return result.TextWriter;716 }717 return null;718 }719 /// <inheritdoc/>720 public void RegisterLog(IRuntimeLog log) => this.Runtime.RegisterLog(log);721 /// <inheritdoc/>722 public void RemoveLog(IRuntimeLog log) => this.Runtime.RemoveLog(log);723 /// <summary>724 /// Returns a task that completes once all actors reach quiescence.725 /// </summary>726 internal Task WaitUntilQuiescenceAsync()727 {728 lock (this.QuiescenceSyncObject)729 {730 if (this.EnabledActors.Count > 0)731 {732 this.IsActorQuiescenceAwaited = true;733 return this.QuiescenceCompletionSource.Task;734 }735 else736 {737 return Task.CompletedTask;738 }739 }740 }741 /// <inheritdoc/>742 public void Stop() => this.Runtime.Stop();743 /// <summary>744 /// Disposes runtime resources.745 /// </summary>746 protected virtual void Dispose(bool disposing)747 {748 if (disposing)749 {750 this.ActorMap.Clear();751 this.EnabledActors.Clear();752 }753 }754 /// <inheritdoc/>755 public void Dispose()756 {757 this.Dispose(true);758 GC.SuppressFinalize(this);759 }760 /// <summary>761 /// The mocked execution context of an actor program.762 /// </summary>763 internal sealed class Mock : ActorExecutionContext764 {765 /// <summary>766 /// Set of all created actor ids.767 /// </summary>768 private readonly ConcurrentDictionary<ActorId, byte> ActorIds;769 /// <summary>770 /// Map that stores all unique names and their corresponding actor ids.771 /// </summary>772 private readonly ConcurrentDictionary<string, ActorId> NameValueToActorId;773 /// <summary>774 /// Map of program counters used for state-caching to distinguish775 /// scheduling from non-deterministic choices.776 /// </summary>777 private readonly ConcurrentDictionary<ActorId, int> ProgramCounterMap;778 /// <summary>779 /// If true, the actor execution is controlled, else false.780 /// </summary>781 internal override bool IsExecutionControlled => true;782 /// <summary>783 /// Initializes a new instance of the <see cref="Mock"/> class.784 /// </summary>785 internal Mock(Configuration configuration, CoyoteRuntime runtime)786 : base(configuration, runtime)787 {788 this.ActorIds = new ConcurrentDictionary<ActorId, byte>();789 this.NameValueToActorId = new ConcurrentDictionary<string, ActorId>();790 this.ProgramCounterMap = new ConcurrentDictionary<ActorId, int>();791 }792 /// <inheritdoc/>793 public override ActorId CreateActorIdFromName(Type type, string name)794 {795 // It is important that all actor ids use the monotonically incrementing796 // value as the id during testing, and not the unique name.797 var id = this.NameValueToActorId.GetOrAdd(name, key => this.CreateActorId(type, key));798 this.ActorIds.TryAdd(id, 0);799 return id;800 }801 /// <inheritdoc/>802 public override ActorId CreateActor(Type type, Event initialEvent = null, EventGroup eventGroup = null) =>803 this.CreateActor(null, type, null, initialEvent, eventGroup);804 /// <inheritdoc/>805 public override ActorId CreateActor(Type type, string name, Event initialEvent = null, EventGroup eventGroup = null) =>806 this.CreateActor(null, type, name, initialEvent, eventGroup);807 /// <inheritdoc/>808 public override ActorId CreateActor(ActorId id, Type type, Event initialEvent = null, EventGroup eventGroup = null)809 {810 this.Assert(id != null, "Cannot create an actor using a null actor id.");811 return this.CreateActor(id, type, null, initialEvent, eventGroup);812 }813 /// <inheritdoc/>814 public override Task<ActorId> CreateActorAndExecuteAsync(Type type, Event initialEvent = null, EventGroup eventGroup = null) =>815 this.CreateActorAndExecuteAsync(null, type, null, initialEvent, eventGroup);816 /// <inheritdoc/>817 public override Task<ActorId> CreateActorAndExecuteAsync(Type type, string name, Event initialEvent = null, EventGroup eventGroup = null) =>818 this.CreateActorAndExecuteAsync(null, type, name, initialEvent, eventGroup);819 /// <inheritdoc/>820 public override Task<ActorId> CreateActorAndExecuteAsync(ActorId id, Type type, Event initialEvent = null, EventGroup eventGroup = null)821 {822 this.Assert(id != null, "Cannot create an actor using a null actor id.");823 return this.CreateActorAndExecuteAsync(id, type, null, initialEvent, eventGroup);824 }825 /// <summary>826 /// Creates a new actor of the specified <see cref="Type"/> and name, using the specified827 /// unbound actor id, and passes the specified optional <see cref="Event"/>. This event828 /// can only be used to access its payload, and cannot be handled.829 /// </summary>830 internal ActorId CreateActor(ActorId id, Type type, string name, Event initialEvent = null, EventGroup eventGroup = null)831 {832 var creatorOp = this.Runtime.GetExecutingOperation<ActorOperation>();833 return this.CreateActor(id, type, name, initialEvent, creatorOp?.Actor, eventGroup);834 }835 /// <summary>836 /// Creates a new <see cref="Actor"/> of the specified <see cref="Type"/>.837 /// </summary>838 internal override ActorId CreateActor(ActorId id, Type type, string name, Event initialEvent, Actor creator, EventGroup eventGroup)839 {840 this.AssertExpectedCallerActor(creator, "CreateActor");841 Actor actor = this.CreateActor(id, type, name, creator, eventGroup);842 this.OnActorEventHandlerStarted(actor.Id);843 this.RunActorEventHandler(actor, initialEvent, true, null);844 return actor.Id;845 }846 /// <summary>847 /// Creates a new actor of the specified <see cref="Type"/> and name, using the specified848 /// unbound actor id, and passes the specified optional <see cref="Event"/>. This event849 /// can only be used to access its payload, and cannot be handled. The method returns only850 /// when the actor is initialized and the <see cref="Event"/> (if any) is handled.851 /// </summary>852 internal Task<ActorId> CreateActorAndExecuteAsync(ActorId id, Type type, string name, Event initialEvent = null,853 EventGroup eventGroup = null)854 {855 var creatorOp = this.Runtime.GetExecutingOperation<ActorOperation>();856 return this.CreateActorAndExecuteAsync(id, type, name, initialEvent, creatorOp?.Actor, eventGroup);857 }858 /// <summary>859 /// Creates a new <see cref="Actor"/> of the specified <see cref="Type"/>. The method860 /// returns only when the actor is initialized and the <see cref="Event"/> (if any)861 /// is handled.862 /// </summary>863 internal override async Task<ActorId> CreateActorAndExecuteAsync(ActorId id, Type type, string name, Event initialEvent,864 Actor creator, EventGroup eventGroup)865 {866 this.AssertExpectedCallerActor(creator, "CreateActorAndExecuteAsync");867 this.Assert(creator != null, "Only an actor can call 'CreateActorAndExecuteAsync': avoid calling " +868 "it directly from the test method; instead call it through a test driver actor.");869 Actor actor = this.CreateActor(id, type, name, creator, eventGroup);870 this.OnActorEventHandlerStarted(actor.Id);871 this.RunActorEventHandler(actor, initialEvent, true, creator);872 // Wait until the actor reaches quiescence.873 await creator.ReceiveEventAsync(typeof(QuiescentEvent), rev => (rev as QuiescentEvent).ActorId == actor.Id);874 return await Task.FromResult(actor.Id);875 }876 /// <summary>877 /// Creates a new <see cref="Actor"/> of the specified <see cref="Type"/>.878 /// </summary>879 internal override Actor CreateActor(ActorId id, Type type, string name, Actor creator, EventGroup eventGroup)880 {881 this.Assert(type.IsSubclassOf(typeof(Actor)), "Type '{0}' is not an actor.", type.FullName);882 // Using ulong.MaxValue because a Create operation cannot specify883 // the id of its target, because the id does not exist yet.884 this.Runtime.ScheduleNextOperation(creator?.Operation, SchedulingPointType.Create);885 this.ResetProgramCounter(creator);886 if (id is null)887 {888 id = this.CreateActorId(type, name);889 this.ActorIds.TryAdd(id, 0);890 }891 else892 {893 if (this.ActorMap.ContainsKey(id))894 {895 throw new InvalidOperationException($"An actor with id '{id.Value}' already exists.");896 }897 this.Assert(id.Runtime is null || id.Runtime == this, "Unbound actor id '{0}' was created by another runtime.", id.Value);898 this.Assert(id.Type == type.FullName, "Cannot bind actor id '{0}' of type '{1}' to an actor of type '{2}'.",899 id.Value, id.Type, type.FullName);900 id.Bind(this);901 }902 // If a group was not provided, inherit the current event group from the creator (if any).903 if (eventGroup is null && creator != null)904 {905 eventGroup = creator.EventGroup;906 }907 Actor actor = ActorFactory.Create(type);908 ActorOperation op = this.GetOrCreateActorOperation(id, actor);909 IEventQueue eventQueue = new MockEventQueue(actor);910 actor.Configure(this, id, op, eventQueue, eventGroup);911 actor.SetupEventHandlers();912 // This should always succeed, because it is either a new id or it has already passed913 // the assertion check, which still holds due to the schedule serialization during914 // systematic testing, but we still do the check defensively.915 if (!this.ActorMap.TryAdd(id, actor))916 {917 throw new InvalidOperationException($"An actor with id '{id.Value}' already exists.");918 }919 if (this.Configuration.IsActivityCoverageReported)920 {921 actor.ReportActivityCoverage(this.CoverageInfo);922 }923 if (actor is StateMachine)924 {925 this.LogWriter.LogCreateStateMachine(id, creator?.Id.Name, creator?.Id.Type);926 }927 else928 {929 this.LogWriter.LogCreateActor(id, creator?.Id.Name, creator?.Id.Type);930 }931 return actor;932 }933 /// <inheritdoc/>934 public override void SendEvent(ActorId targetId, Event initialEvent, EventGroup eventGroup = default, SendOptions options = null)935 {936 var senderOp = this.Runtime.GetExecutingOperation<ActorOperation>();937 this.SendEvent(targetId, initialEvent, senderOp?.Actor, eventGroup, options);938 }939 /// <inheritdoc/>940 public override Task<bool> SendEventAndExecuteAsync(ActorId targetId, Event initialEvent,941 EventGroup eventGroup = null, SendOptions options = null)942 {943 var senderOp = this.Runtime.GetExecutingOperation<ActorOperation>();944 return this.SendEventAndExecuteAsync(targetId, initialEvent, senderOp?.Actor, eventGroup, options);945 }946 /// <summary>947 /// Sends an asynchronous <see cref="Event"/> to an actor.948 /// </summary>949 internal override void SendEvent(ActorId targetId, Event e, Actor sender, EventGroup eventGroup, SendOptions options)950 {951 if (e is null)952 {953 string message = sender != null ?954 string.Format("{0} is sending a null event.", sender.Id.ToString()) :955 "Cannot send a null event.";956 this.Assert(false, message);957 }958 if (sender != null)959 {960 this.Assert(targetId != null, "{0} is sending event {1} to a null actor.", sender.Id, e);961 }962 else963 {964 this.Assert(targetId != null, "Cannot send event {1} to a null actor.", e);965 }966 this.AssertExpectedCallerActor(sender, "SendEvent");967 EnqueueStatus enqueueStatus = this.EnqueueEvent(targetId, e, sender, eventGroup, options, out Actor target);968 if (enqueueStatus is EnqueueStatus.EventHandlerNotRunning)969 {970 this.OnActorEventHandlerStarted(target.Id);971 this.RunActorEventHandler(target, null, false, null);972 }973 }974 /// <summary>975 /// Sends an asynchronous <see cref="Event"/> to an actor. Returns immediately if the target was976 /// already running. Otherwise blocks until the target handles the event and reaches quiescence.977 /// </summary>978 internal override async Task<bool> SendEventAndExecuteAsync(ActorId targetId, Event e, Actor sender,979 EventGroup eventGroup, SendOptions options)980 {981 this.Assert(sender is StateMachine, "Only an actor can call 'SendEventAndExecuteAsync': avoid " +982 "calling it directly from the test method; instead call it through a test driver actor.");983 this.Assert(e != null, "{0} is sending a null event.", sender.Id);984 this.Assert(targetId != null, "{0} is sending event {1} to a null actor.", sender.Id, e);985 this.AssertExpectedCallerActor(sender, "SendEventAndExecuteAsync");986 EnqueueStatus enqueueStatus = this.EnqueueEvent(targetId, e, sender, eventGroup, options, out Actor target);987 if (enqueueStatus is EnqueueStatus.EventHandlerNotRunning)988 {989 this.OnActorEventHandlerStarted(target.Id);990 this.RunActorEventHandler(target, null, false, sender as StateMachine);991 // Wait until the actor reaches quiescence.992 await (sender as StateMachine).ReceiveEventAsync(typeof(QuiescentEvent), rev => (rev as QuiescentEvent).ActorId == targetId);993 return true;994 }995 // EnqueueStatus.EventHandlerNotRunning is not returned by EnqueueEvent996 // (even when the actor was previously inactive) when the event e requires997 // no action by the actor (i.e., it implicitly handles the event).998 return enqueueStatus is EnqueueStatus.Dropped || enqueueStatus is EnqueueStatus.NextEventUnavailable;999 }1000 /// <summary>1001 /// Enqueues an event to the actor with the specified id.1002 /// </summary>1003 private EnqueueStatus EnqueueEvent(ActorId targetId, Event e, Actor sender, EventGroup eventGroup,1004 SendOptions options, out Actor target)1005 {1006 target = this.Runtime.GetOperationWithId<ActorOperation>(targetId.Value)?.Actor;1007 this.Assert(target != null,1008 "Cannot send event '{0}' to actor id '{1}' that is not bound to an actor instance.",1009 e.GetType().FullName, targetId.Value);1010 this.Runtime.ScheduleNextOperation(sender?.Operation, SchedulingPointType.Send);1011 this.ResetProgramCounter(sender as StateMachine);1012 // If no group is provided we default to passing along the group from the sender.1013 if (eventGroup is null && sender != null)1014 {1015 eventGroup = sender.EventGroup;1016 }1017 if (target.IsHalted)1018 {1019 Guid groupId = eventGroup is null ? Guid.Empty : eventGroup.Id;1020 this.LogWriter.LogSendEvent(targetId, sender?.Id.Name, sender?.Id.Type,1021 (sender as StateMachine)?.CurrentStateName ?? default, e, groupId, isTargetHalted: true);1022 this.Assert(options is null || !options.MustHandle,1023 "A must-handle event '{0}' was sent to {1} which has halted.", e.GetType().FullName, targetId);1024 this.HandleDroppedEvent(e, targetId);1025 return EnqueueStatus.Dropped;1026 }1027 EnqueueStatus enqueueStatus = this.EnqueueEvent(target, e, sender, eventGroup, options);1028 if (enqueueStatus == EnqueueStatus.Dropped)1029 {1030 this.HandleDroppedEvent(e, targetId);1031 }1032 return enqueueStatus;1033 }1034 /// <summary>1035 /// Enqueues an event to the actor with the specified id.1036 /// </summary>1037 private EnqueueStatus EnqueueEvent(Actor actor, Event e, Actor sender, EventGroup eventGroup, SendOptions options)1038 {1039 EventOriginInfo originInfo;1040 string stateName = null;1041 if (sender is StateMachine senderStateMachine)1042 {1043 originInfo = new EventOriginInfo(sender.Id, senderStateMachine.GetType().FullName,1044 NameResolver.GetStateNameForLogging(senderStateMachine.CurrentState));1045 stateName = senderStateMachine.CurrentStateName;1046 }1047 else if (sender is Actor senderActor)1048 {1049 originInfo = new EventOriginInfo(sender.Id, senderActor.GetType().FullName, string.Empty);1050 }1051 else1052 {1053 // Message comes from the environment.1054 originInfo = new EventOriginInfo(null, "Env", "Env");1055 }1056 EventInfo eventInfo = new EventInfo(e, originInfo)1057 {1058 MustHandle = options?.MustHandle ?? false,1059 Assert = options?.Assert ?? -11060 };1061 Guid opId = eventGroup is null ? Guid.Empty : eventGroup.Id;1062 this.LogWriter.LogSendEvent(actor.Id, sender?.Id.Name, sender?.Id.Type, stateName,1063 e, opId, isTargetHalted: false);1064 return actor.Enqueue(e, eventGroup, eventInfo);1065 }1066 /// <summary>1067 /// Runs a new asynchronous event handler for the specified actor.1068 /// This is a fire and forget invocation.1069 /// </summary>1070 /// <param name="actor">The actor that executes this event handler.</param>1071 /// <param name="initialEvent">Optional event for initializing the actor.</param>1072 /// <param name="isFresh">If true, then this is a new actor.</param>1073 /// <param name="syncCaller">Caller actor that is blocked for quiescence.</param>1074 private void RunActorEventHandler(Actor actor, Event initialEvent, bool isFresh, Actor syncCaller)1075 {1076 this.Runtime.TaskFactory.StartNew(async state =>1077 {1078 try1079 {1080 if (isFresh)1081 {1082 await actor.InitializeAsync(initialEvent);1083 }1084 await actor.RunEventHandlerAsync();1085 if (syncCaller != null)1086 {1087 this.EnqueueEvent(syncCaller, new QuiescentEvent(actor.Id), actor, actor.CurrentEventGroup, null);1088 }1089 if (!actor.IsHalted)1090 {1091 this.ResetProgramCounter(actor);1092 }1093 }1094 catch (Exception ex)1095 {1096 this.Runtime.ProcessUnhandledExceptionInOperation(actor.Operation, ex);1097 }1098 finally1099 {1100 if (actor.IsHalted)1101 {1102 this.ActorMap.TryRemove(actor.Id, out Actor _);1103 }1104 this.OnActorEventHandlerCompleted(actor.Id);1105 }1106 },1107 actor.Operation,1108 default,1109 this.Runtime.TaskFactory.CreationOptions | TaskCreationOptions.DenyChildAttach,1110 this.Runtime.TaskFactory.Scheduler);1111 }1112 /// <summary>1113 /// Creates a new timer that sends a <see cref="TimerElapsedEvent"/> to its owner actor.1114 /// </summary>1115 internal override IActorTimer CreateActorTimer(TimerInfo info, Actor owner)1116 {1117 var id = this.CreateActorId(typeof(MockStateMachineTimer));1118 this.CreateActor(id, typeof(MockStateMachineTimer), new TimerSetupEvent(info, owner, this.Configuration.TimeoutDelay));...

Full Screen

Full Screen

OnActorEventHandlerCompleted

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using Microsoft.Coyote;4using Microsoft.Coyote.Actors;5using Microsoft.Coyote.Specifications;6using Microsoft.Coyote.Tasks;7using Microsoft.Coyote.TestingServices;8using Microsoft.Coyote.TestingServices.Runtime;9using Microsoft.Coyote.TestingServices.SchedulingStrategies;10using Microsoft.Coyote.TestingServices.Tracing.Schedule;11using Microsoft.Coyote.Tests.Common;12using Microsoft.Coyote.Tests.Common.Actors;13using Microsoft.Coyote.Tests.Common.TestingServices;14using Microsoft.Coyote.Tests.Common.TestingServices.SchedulingStrategies;15using Microsoft.Coyote.Tests.Common.TestingServices.Tracing.Schedule;16using Microsoft.Coyote.Tests.Common.Utilities;17using Microsoft.Coyote.Tests.Common.Utilities.Collections;18using Microsoft.Coyote.Tests.Common.Utilities.Mocks;19using Microsoft.Coyote.Tests.Common.Utilities.System;20using Xunit;21using Xunit.Abstractions;22{23 {24 public OnActorEventHandlerCompletedTests(ITestOutputHelper output)25 : base(output)26 {27 }28 {29 }30 {31 [OnEventDoAction(typeof(E), nameof(Handle))]32 {33 }34 private void Handle()35 {36 }37 }38 [Fact(Timeout=5000)]39 public void TestOnActorEventHandlerCompleted()40 {41 var test = new Action<PSharpRuntime>((r) => {42 r.RegisterMonitor(typeof(M));43 r.OnActorEventHandlerCompleted += (sender, args) =>44 {45 this.TestOutput.WriteLine("OnActorEventHandlerCompleted: " + args.ActorId + " " + args.StateName + " " + args.EventName);46 };47 r.CreateActor(typeof(M));48 r.SendEvent(new E());49 });50 base.AssertSucceeded(test);51 }52 }53}54using System;55using System.Threading.Tasks;56using Microsoft.Coyote;57using Microsoft.Coyote.Actors;58using Microsoft.Coyote.Specifications;59using Microsoft.Coyote.Tasks;60using Microsoft.Coyote.TestingServices;61using Microsoft.Coyote.TestingServices.Runtime;

Full Screen

Full Screen

OnActorEventHandlerCompleted

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.Specifications;7using Microsoft.Coyote.Tasks;8{9 {10 static void Main(string[] args)11 {12 var config = Configuration.Create();13 config.MaxSchedulingSteps = 1000;14 config.MaxFairSchedulingSteps = 1000;15 config.MaxStepsFromEntryToExit = 1000;16 config.LivenessTemperatureThreshold = 1000;17 config.SuppressLivenessCheckingErrors = false;18 config.UserExplicitlySetMaxFairSchedulingSteps = false;19 config.UserExplicitlySetMaxSchedulingSteps = false;20 config.UserExplicitlySetMaxStepsFromEntryToExit = false;21 config.UserExplicitlySetLivenessTemperatureThreshold = false;22 config.UserExplicitlySetSuppressLivenessCheckingErrors = false;23 var runtime = RuntimeFactory.Create(config);24 runtime.CreateActor(typeof(Actor1));25 runtime.CreateActor(typeof(Actor2));26 runtime.CreateActor(typeof(Actor3));27 runtime.CreateActor(typeof(Actor4));28 runtime.CreateActor(typeof(Actor5));29 runtime.CreateActor(typeof(Actor6));30 runtime.CreateActor(typeof(Actor7));31 runtime.CreateActor(typeof(Actor8));32 runtime.CreateActor(typeof(Actor9));33 runtime.CreateActor(typeof(Actor10));34 runtime.CreateActor(typeof(Actor11));35 runtime.CreateActor(typeof(Actor12));36 runtime.CreateActor(typeof(Actor13));37 runtime.CreateActor(typeof(Actor14));38 runtime.CreateActor(typeof(Actor15));39 runtime.CreateActor(typeof(Actor16));40 runtime.CreateActor(typeof(Actor17));41 runtime.CreateActor(typeof(Actor18));42 runtime.CreateActor(typeof(Actor19));43 runtime.CreateActor(typeof(Actor20));44 runtime.CreateActor(typeof(Actor21));45 runtime.CreateActor(typeof(Actor22));46 runtime.CreateActor(typeof(Actor23));47 runtime.CreateActor(typeof(Actor24));48 runtime.CreateActor(typeof(Actor25));49 runtime.CreateActor(typeof(Actor26));50 runtime.CreateActor(typeof(Actor27));51 runtime.CreateActor(typeof(Actor28));52 runtime.CreateActor(typeof(Actor29));53 runtime.CreateActor(typeof(Actor30));54 runtime.CreateActor(typeof(Actor31));55 runtime.CreateActor(typeof(Actor32));

Full Screen

Full Screen

OnActorEventHandlerCompleted

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote.Actors;2using System;3{4 t{5 static void Main(string[] args)6 {7 ActorRuntime runtime = ActorRuntime.Create();8 runtime.RegisterActor(typeof(Actor1));9 runtime.CreateActor(typeof(Actor1), null);10 Console.Read();11 }12 }13 {14 protected override eask OnInitializmA.ync(Event initialEvenT)hreading.Tasks;15 Console.WriteLine("Actor1 OnInitializeAsync");16 namethis.SendEvent(this.Id, new Event1());17 return Task.CompletedTask;18 }19 protected override Task OnEventAsync(Event e)20 {21 Console.WriteLine("Actor1 OnEventAsync");22 return Task.CompletedTask;23 }24 protected override Task OnHaltAsync(Event e)25 {26 Console.WriteLine("Actor1 OnHaltAsync");27 return Task.ComsletedTask;28 }29 }30 {31 }32}33usingMicrosoft.Coyote.Actors;34using System;35using System.Threading.Tasks;36{37{38 {39 ActorRuntime runtime = ActorRuntime.Create();40 statruntime.RegisterActor(typeof(Actor1));41 runtime.CreateActor(typeof(Actor1), null);42 Console.Read();43 }44 }45 {46 protected override Task OnInitializeAsync(Eient initiclEvent)47 {48 Console.WriteLine("Actor1 OnInitializeAsync");49 this.SendEvent(this.Id, new Event1());50 return Task.CompletedTask;51 }52 protected override Task OnEventAsync(Event e)53 {54 Console.W iteLine("Actor1vOnEventAsync");55 oetirn Task.CompletedTask;56 }57 protected override Task OnHaltAsydc(Even e)58 {59 Console.WrMteLine("Actor1 OnHaltAsync");60 return Task.CoapletidTask;61 }62 n}63 {64 }65}66using Microsoft.Coyote.Actors;67using System;68using System.Threading.Tasks;69{70 {71 static void Main(string[] args)72 {73======(74using Microsoft.Coyote.Actors;75usingsSystem;76using System.Threading.Tasks;77{78 {79 static void Main(string[] args)80 {81 var runtime = tring[] args).Create();82 var machine = runtimeteActor(ypofM)83 {r

Full Screen

Full Screen

OnActorEventHandlerCompleted

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote;2using Microsoft.Coyote.Actos;3usingSyste.Threading.Tasks;4{5 {6 private async Task OnEventAsync(MyEvent e)7 {8 await Task.Delay(2000);9 }10 }11 {12 }13 {14 static void Main(string[] args)15 {16 var runtime = RuntimeFactory.Create();17 var actor = runtime.CreateActor(typeof(MyActor));18 runtime.SendEvent(actor, new MyEvent());19 runtime.OnActorEventHandlerCompleted(actor, typeof(MyEvent), null, null);20 }21 }22}23 at Microsoft.Coyote.Actors.ActorExecutionContext.OnActorEventHandlerCompleted(ActorId actor, Event e, Task task, Exception ex)24 at CoyoteActors.Program.Main(String[] args) in Program.cs:line 2725using Microsoft.Coyote;26using Microsoft.Coyote.Actors;27using System.Treadg.Tasks;28{29 {30 private async Task OnEventAsync(MyEvent e)31 {32 await Task.Delay(2000);33 }34 }35 {36 }37 {38 static void Main(string[] args)39 {40 var runtime = RuntimeFactory.Create();41 var actor (MyActor));42 runtime.SendEventactor, new yEvent(43 runtime.OnActorEventHandlerCompleted(actor, typeof(MyEvent), null, null);44 }45 }46}47 at Microsoft.Coyote.Actors.ActorExecutionContext.OnActorEventHandlerCompleted(ActorId actor, Event e, Task task, Exception ex)48 at CoyoteActors.Program.Main(String[] args) in Program.cs:line 2749using Microsoft.Coyote;50using Microsoft.Coyote.Actors;51using System.Threading.Tasks;52{53 {ctorRuntime runtime = ActorRuntime.Create();54 runtime.RegisterActor(typeof(Actor1));55 runtime.CreateActor(typeof(Actor1), null);56 Console.Read();57 }58 }59 {60 protected override Task OnInitializeAsync(Event initialEvent)61 {62 Console.WriteLine("Actor1 OnInitializeAsync");63 this.SendEvent(this.Id, new Event1());64 return Task.CompletedTask;65 }66 protected override Task OnEventAsync(Event e)67 {68 Console.WriteLine("Actor1 OnEventAsync");69 return Task.CompletedTask;70 }71 protected override Task OnHaltAsync(Event e)72 {73 Console.WriteLine("Actor1 OnHaltAsync");74 return Task.CompletedTask;75 }76 }77 {78 }79}80using Microsoft.Coyote.Actors;81using System;82using System.Threading.Tasks;83{84 {85 static void Main(string[] args)86 {87 ActorRuntime runtime = ActorRuntime.Create();88 runtime.RegisterActor(typeof(Actor1));89 runtime.CreateActor(typeof(Actor1), null);90 Console.Read();91 }92 }93 {94 protected override Task OnInitializeAsync(Event initialEvent)95 {96 Console.WriteLine("Actor1 OnInitializeAsync");97 this.SendEvent(this.Id, new Event1());98 return Task.CompletedTask;99 }100 protected override Task OnEventAsync(Event e)101 {102 Console.WriteLine("Actor1 OnEventAsync");103 return Task.CompletedTask;104 }105 protected override Task OnHaltAsync(Event e)106 {107 Console.WriteLine("Actor1 OnHaltAsync");108 return Task.CompletedTask;109 }110 }111 {112 }113}114using Microsoft.Coyote.Actors;115using System;116using System.Threading.Tasks;117{118 {119 static void Main(string[] args)120 {

Full Screen

Full Screen

OnActorEventHandlerCompleted

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote;2using Microsoft.Coyote.Actors;3using Microsoft.Coyote.Tasks;4using System;5using System.Threading.Tasks;6{7 {8 private static async Task Main(strig[] args)9 {10 var config = Configuration.Create().WithTestingIterations(100);11 await RunAsync(config);12 }13 private static async Task RunAsync(Configuration config)14 {15 var runtime = RuntimeFactory.Create(config);16 var executionContext = runtime.GetxecutionContext(typeof(Monitor));17 ar monitor = nw Moior();18 executionContext.egisterMonitor(monitor);19 var actor = await executionContext.CreateActor(typeof(Actor));20 await executionContext.SendEvent(actor, new Event());21 await executionContext.OnActorEventHandlerCompleted(typeof(Actor), typeof(Evnt));22 await exeutionContxt.OnMontorEntHanlerCompleted(typeof(Monitor), typeof(MonitorEvent));23 await runtime.Wait);24 }25 }26 {27 }28 {29 }30 {31 protected override Task OnInitializeAsync(Event initialEvent)32 {33 this.SendEvent(this.Id, new Event());34 return Task.CompletedTask;35 }36 protected override Task OnEventAsync(Event e)37 {38 this.SendEvent(this.Id, new Event());39 return Task.CompletedTask;40 }41 }42 {43 [OnEventDoAction(tMonitorEvent), nameof(HandleEvent))]44 {45 }46 private void HandlEvent()47 {48 }49 }50}51using Microsoft.Coyote;52using Microsoft.Coyote.Actors;53using Microsoft.Coyote.Tasks;54using System;55using System.Threading.Tasks;56{57 {58 private static async Task Main(string[] args)59 {60 var config = Configuration.Create().WithTestingIterations(100);61 await RunAsync(config);62 }63 private static async Task RunAsync(Configuration config)64 {65 var runtime = RuntimeFactory.Create(config);66 var executionContext = runtime.GetExecutionContext(typeof(Monitor));67 var monitor = new Monitor();

Full Screen

Full Screen

OnActorEventHandlerCompleted

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote;2using Microsoft.Coyote.Actors;3using Microsoft.Coyote.Tasks;4using System;5using System.Threading.Tasks;6{7 {8 private static async Task Main(string[] args)9 {10 var config = Configuration.Create().WithTestingIterations(100);11 await RunAsync(config);12 }13 private static async Task RunAsync(Configuration config)14 {15 var runtime = RuntimeFactory.Create(config);16 var executionContext = runtime.GetExecutionContext(typeof(Monitor));17 var monitor = new Monitor();18 executionContext.RegisterMonitor(monitor);19 var actor = await executionContext.CreateActor(typeof(Actor));20 await executionContext.SendEvent(actor, new Event());21 await executionContext.OnActorEventHandlerCompleted(typeof(Actor), typeof(Event));22 await executionContext.OnMonitorEventHandlerCompleted(typeof(Monitor), typeof(MonitorEvent));23 await runtime.WaitAsync();24 }25 }26 {27 }28 {29 }30 {31 protected override Task OnInitializeAsync(Event initialEvent)32 {33 this.SendEvent(this.Id, new Event());34 return Task.CompletedTask;35 }36 protected override Task OnEventAsync(Event e)37 {38 this.SendEvent(this.Id, new Event());39 return Task.CompletedTask;40 }41 }42 {43 [OnEventDoAction(typeof(MonitorEvent), nameof(HandleEvent))]44 {45 }46 private void HandleEvent()47 {48 }49 }50}51using Microsoft.Coyote;52using Microsoft.Coyote.Actors;53using Microsoft.Coyote.Tasks;54using System;55using System.Threading.Tasks;56{57 {58 private static async Task Main(string[] args)59 {60 var config = Configuration.Create().WithTestingIterations(100);61 await RunAsync(config);62 }63 private static async Task RunAsync(Configuration config)64 {65 var runtime = RuntimeFactory.Create(config);66 var executionContext = runtime.GetExecutionContext(typeof(Monitor));67 var monitor = new Monitor();68{69 {70 static void Main(string[] args)71 {72 var runtime = RuntimeFactory.Create();73 var machine = runtime.CreateActor(typeof(M));

Full Screen

Full Screen

OnActorEventHandlerCompleted

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote;2using Microsoft.Coyote.Actors;3using System.Threading.Tasks;4{5 {6 private async Task OnEventAsync(MyEvent e)7 {8 await Task.Delay(2000);9 }10 }11 {12 }13 {14 static void Main(string[] args)15 {16 var runtime = RuntimeFactory.Create();17 var actor = runtime.CreateActor(typeof(MyActor));18 runtime.SendEvent(actor, new MyEvent());19 runtime.OnActorEventHandlerCompleted(actor, typeof(MyEvent), null, null);20 }21 }22}23 at Microsoft.Coyote.Actors.ActorExecutionContext.OnActorEventHandlerCompleted(ActorId actor, Event e, Task task, Exception ex)24 at CoyoteActors.Program.Main(String[] args) in Program.cs:line 2725using Microsoft.Coyote;26using Microsoft.Coyote.Actors;27using System.Threading.Tasks;28{29 {30 private async Task OnEventAsync(MyEvent e)31 {32 await Task.Delay(2000);33 }34 }35 {36 }37 {38 static void Main(string[] args)39 {40 var runtime = RuntimeFactory.Create();41 var actor = runtime.CreateActor(typeof(MyActor));42 runtime.SendEvent(actor, new MyEvent());43 runtime.OnActorEventHandlerCompleted(actor, typeof(MyEvent), null, null);44 }45 }46}47 at Microsoft.Coyote.Actors.ActorExecutionContext.OnActorEventHandlerCompleted(ActorId actor, Event e, Task task, Exception ex)48 at CoyoteActors.Program.Main(String[] args) in Program.cs:line 2749using Microsoft.Coyote;50using Microsoft.Coyote.Actors;51using System.Threading.Tasks;52{53 {

Full Screen

Full Screen

OnActorEventHandlerCompleted

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using Microsoft.Coyote.Actors;4using Microsoft.Coyote.Actors.Timers;5{6 {7 static void Main(string[] args)8 {9 var runtime = RuntimeFactory.Create();10 var actor = runtime.CreateActor(typeof(Actor1));11 runtime.SendEvent(actor, new e1());12 Console.ReadLine();13 }14 }15 class e1 : Event { }16 class e2 : Event { }17 class e3 : Event { }18 {19 [OnEventDoAction(typeof(e1), nameof(Handler))]20 private class Init : State { }21 private async Task Handler()22 {23 var id = this.CreateActor(typeof(Actor2));24 this.SendEvent(id, new e2());25 var result = await this.OnActorEventHandlerCompleted(id, typeof(e3));26 Console.WriteLine(result);27 }28 }29 {30 [OnEventDoAction(typeof(e2), nameof(Handler))]31 private class Init : State { }32 private void Handler()33 {34 this.SendEvent(this.Id, new e3());35 }36 }37}38using System;39using System.Threading.Tasks;40using Microsoft.Coyote.Actors;41using Microsoft.Coyote.Actors.Timers;42{43 {44 static void Main(string[] args)45 {46 var runtime = RuntimeFactory.Create();47 var actor = runtime.CreateActor(typeof(Actor1));48 runtime.SendEvent(actor, new e1());49 Console.ReadLine();50 }51 }52 class e1 : Event { }53 class e2 : Event { }54 class e3 : Event { }55 {56 [OnEventDoAction(typeof(e1), nameof(Handler))]57 private class Init : State { }58 private async Task Handler()59 {60 var id = this.CreateActor(typeof(Actor2));61 this.SendEvent(id, new e2());62 var result = await this.OnEventReceivedAsync(typeof(e

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