Added checks in CoyoteRuntime.RunTestAsync() to check testMethod if it is either a Action<ICoyoteRuntime> or Func<ICoyoteRuntime, Task> delegate type before calling the runtime extension RunTest() method#509
Open
kzdev-net wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…t is either a Action<ICoyoteRuntime> or Func<ICoyoteRuntime, Task> delegate type before calling the runtime extension RunTest() method because for an extension of type ActorExecutionContext, the RunTest method will gladly call one of those delegate types even though it is designed to only handle Action<IActorRuntime> or Func<IActorRuntime, Task>delegate types, but Action<T> and Func<T, Task> generics have a contravarient generic parameter, so ActorExecutionContext will indicate that the delegate was called fine, but other extension types (e.g. NullRuntimeExtension) will not call the methods, so the provided test method might only run if the ActorExecutionContext is the runtime extension, but the test method is not actually the expected type of delegate.
Author
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The runTest that acts as the top-level execution for the ControlledThread that is created in CoyoteRuntime.RunTestAsync first calls
if (this.Extension.RunTest(testMethod, out Task extensionTask))before checking if testMethod is an Action or a Func.
When this.Extension is an ActorExecutionContext, then the RunTest method is implemented like so
However, the Action<T> and Func<T,Task> generic parameter 'T' is contravarient. So, if the testMethod is either an Action<ICoyoteRuntime> or a Func<ICoyoteRuntime, Task>, one of the condition tests will pass, and the method will be executed. Which is fine, but it masks/hides a possible condition where if the runtime extension is not an ActorExecutionContext instance and instead returns false, then the conditional checks in the runTest delegate for the ControlledThread will throw an exception stating that the test delegate type is unsupported even though the TestEngine.Create overloads allow and support such a test method.
There needs to be type checks in the testMethod prior to calling this.Extension.RunTest().