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.
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 theSubscriptionBuilder.ResolveSubscription
method. Although I still don't know exactly why, the execution goes as follows. First, theGetConstructors<TOptions>
extension method is called, returning the constructors that haveTOptions
as a parameter. https://github.com/Eventuous/eventuous/blob/3209ab37dafee320fc563620665e0c06f6c15be1/src/Core/src/Eventuous.Subscriptions/Registrations/SubscriptionBuilder.cs#L194 This extension method returns the constructor and also theTOptions
ParameterInfo
in a tuple. Then, in line 216,GetParameters
is called again to get this constructor parameters and map them to their correct value. https://github.com/Eventuous/eventuous/blob/3209ab37dafee320fc563620665e0c06f6c15be1/src/Core/src/Eventuous.Subscriptions/Registrations/SubscriptionBuilder.cs#L216 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. https://github.com/Eventuous/eventuous/blob/3209ab37dafee320fc563620665e0c06f6c15be1/src/Core/src/Eventuous.Subscriptions/Registrations/SubscriptionBuilder.cs#L224For 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, aSystem.Diagnostics.Debugger.Launch()
is set in line 252 to debug this problem.