You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’ve been running into issues with tests failing periodically in the Akkatecture library I maintain. Looking back, I see that the issue has existed for a while; the original Akkatecture author made note of it. Essentially, the tests are racy, “Heisenbug”-style problems.
While looking for a solution, I see Akka.TestKit has a set of ExpectMsgAllOf methods that can be used for "expecting" a set of messages. It is described as a solution to racy tests here: Debugging Akka.NET. I would like to use something like this to test for a set of events that should exist after a specific domain action. However, aspects of the ExpectMsgAllOf methods make them unsuitable for the purpose:
They require whole objects to be submitted for an equality check, rather than allowing Predicates (as does the ExpectMsg functions).
If the contents of the events resulting from the test are not easily predicted, then using a Predicate to validate individual aspects of each message might suffice.
I'm unable to supply our own value to the parameter areEqual, as it exists only in the private method InternalExpectMsgAllOfAsync<T>(...) (and that would be hackish anyway).
The ExpectMsgAllOf method expects a common message type, T.
In my use-case, events will be a variety of types, all derived from a common ancestor, and the details of the derived type would be required to satisfy the Predicate associated with the particular message.
Proposed Solution
I propose a set of methods named as ExpectMsgAllOfWithPredicates that would allow setting the expectations for sets of messages using predicates. This would be similar to how the ExpectMsg methods accept Predicate<T> as a parameter.
To enable heterogeneous message types in the set, the methods would accept a collection of a new type, PredicateInfo, that would contain the type of the expected input as an instance of Type.
The wrapper class PredicateInfo would have only two properties of the types Delegate and Type. Static helper methods will be supplied as factories for safety and convenience.
The text was updated successfully, but these errors were encountered:
…ates (#6668)
* Add new set of methods and related test to enable "ExpectAll" with Predicates
* Fix generic parameter T
---------
Co-authored-by: Malcolm Learner <mlearner@signifyhealth.com>
Co-authored-by: Gregorius Soedharmo <arkatufus@yahoo.com>
Problem
I’ve been running into issues with tests failing periodically in the Akkatecture library I maintain. Looking back, I see that the issue has existed for a while; the original Akkatecture author made note of it. Essentially, the tests are racy, “Heisenbug”-style problems.
While looking for a solution, I see Akka.TestKit has a set of
ExpectMsgAllOf
methods that can be used for "expecting" a set of messages. It is described as a solution to racy tests here: Debugging Akka.NET. I would like to use something like this to test for a set of events that should exist after a specific domain action. However, aspects of theExpectMsgAllOf
methods make them unsuitable for the purpose:ExpectMsg
functions).areEqual
, as it exists only in the private methodInternalExpectMsgAllOfAsync<T>(...)
(and that would be hackish anyway).ExpectMsgAllOf
method expects a common message type,T
.Proposed Solution
I propose a set of methods named as
ExpectMsgAllOfWithPredicates
that would allow setting the expectations for sets of messages using predicates. This would be similar to how theExpectMsg
methods acceptPredicate<T>
as a parameter.To enable heterogeneous message types in the set, the methods would accept a collection of a new type,
PredicateInfo
, that would contain the type of the expected input as an instance ofType
.The wrapper class
PredicateInfo
would have only two properties of the typesDelegate
andType
. Static helper methods will be supplied as factories for safety and convenience.The text was updated successfully, but these errors were encountered: