Get all parameters at once to avoid conflicts in parallel testing #211
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.
This PR should hopefully close #181.
A testing branch was created here to check the scenario.
As #181 explains, this problem arises when tests are being executed in parallel, randomly throwing
ArgumentNullException
in theAllStreamSubscription
constructor.After debugging this case, this was narrowed down to the
SubscriptionBuilder.ResolveSubscription
method. Although I still don't know exactly why, the execution goes as follows.First, the
GetConstructors<TOptions>
extension method is called, returning the constructors that haveTOptions
as a parameter.eventuous/src/Core/src/Eventuous.Subscriptions/Registrations/SubscriptionBuilder.cs
Line 194 in 3209ab3
This extension method returns the constructor and also the
TOptions
ParameterInfo
in a tuple.Then, in line 216,
GetParameters
is called again to get this constructor parameters and map them to their correct value.eventuous/src/Core/src/Eventuous.Subscriptions/Registrations/SubscriptionBuilder.cs
Line 216 in 3209ab3
Finally, in line 224, a check is run to see if the parameter being mapped to its correct value is the options parameter, to get them from the IMonitorOptions.
eventuous/src/Core/src/Eventuous.Subscriptions/Registrations/SubscriptionBuilder.cs
Line 224 in 3209ab3
For some reason, when working in parallel, although they refer to the same parameter, they are completely different instances and don't match, omitting this check and returning null. To fix it, this PR returns only one array with the parameters of the constructor, avoiding the second call.
In the testing branch mentioned earlier, this behaviour can be replicated with ease. If line 220 is uncommented, test will start to fail, as now the
GetParameters()
method is returning different instances of the parameter.Also, a
System.Diagnostics.Debugger.Launch()
is set in line 252 to debug this problem.