Isaac Abraham
Top achievements
Rank 1
Isaac Abraham
asked on 03 May 2013, 10:53 AM
I'm calling a mock on multiple threads. Sometimes this works just fine. But sometimes the mock call fails with a System.ArgumentException "An item with the same key has already been added.". Here's the end of the stack trace: -
Now I'm not using any dictionaries in my code - is it possible that this is happening somewhere inside the mock?
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at . . (MethodInfo )
at . . (MockInvocation )
at . .Intercept(MockInvocation )
at . .Intercept(MockInvocation )
at . .Intercept(IInvocation )
Now I'm not using any dictionaries in my code - is it possible that this is happening somewhere inside the mock?
12 Answers, 1 is accepted
0
Accepted
Hi Isaac,
Recently we've found a multithreading racing issue inside JustMock. The fix is already committed and will be shipped with the next JustMock release.
Kind regards,
Mihail
the Telerik team
Recently we've found a multithreading racing issue inside JustMock. The fix is already committed and will be shipped with the next JustMock release.
Kind regards,
Mihail
the Telerik team
0
Isaac Abraham
Top achievements
Rank 1
answered on 17 May 2013, 12:04 PM
Any idea when this will be in a public release?
Thanks
Thanks
0
Hi Isaac,
The fix is included in the latest JustMock official build (JustMock 2013 Q1 SP2). Feel free to test if it works as expected for your scenario(s).
Kind regards,
Kaloyan
the Telerik team
The fix is included in the latest JustMock official build (JustMock 2013 Q1 SP2). Feel free to test if it works as expected for your scenario(s).
Kind regards,
Kaloyan
the Telerik team
0
Isaac Abraham
Top achievements
Rank 1
answered on 17 May 2013, 03:24 PM
I have the latest version from nuget. Here's a stack trace I'm getting - again, not sure if this is internal to JM but I can't hit a breakpoint in my code: -
This occurs when calling the following code: -
at Telerik.JustMock.Setup.MethodInstance. . ( )
at System.Collections.Generic.List`1.ForEach(Action`1 action)
at Telerik.JustMock.Setup.MethodInstance.get_NumerOfTimesExecuted()
at . . . ()
at . .Assert(MethodInstance , )
at . . (MethodCall )
at Telerik.JustMock.Mock. (Occurs )
at Telerik.JustMock.Mock. . ( )
at . . [ ]( , Action`1 )
at Telerik.JustMock.Mock.Assert(Expression`1 expression, Args args, Occurs occurs)
This occurs when calling the following code: -
Mock.Assert(() => mock.Foo(
null
,
null
,
null
), Args.Ignore(), Occurs.Exactly(5));
0
Hi again Isaac,
Is it possible to send us a sample project reproducing the issue. This will allow us to investigate it further and provide a proper solution.
Thanks in advance.
Greetings,
Kaloyan
the Telerik team
Is it possible to send us a sample project reproducing the issue. This will allow us to investigate it further and provide a proper solution.
Thanks in advance.
Greetings,
Kaloyan
the Telerik team
0
Isaac Abraham
Top achievements
Rank 1
answered on 03 Jun 2013, 01:19 PM
Here's a sample of an error I'm seeing with the latest version of JustMock: -
With the latest version of JustMock on nuget (2013.2.522), this fails the second test consistently. However, if you roll back to an older version of (2013.1.507), it works.
I've tried this with both Xunit and Nunit, same thing happens.
[TestFixture]
public
class
AsyncTests
{
[Test]
public
async Task
FirstTest()
{
var svc = Mock.Create<TestAsyncService>();
Mock.Arrange(() => svc.DoSomethingAsync()).Returns(Task.Run(() => { }));
await svc.DoSomethingAsync();
Mock.Assert(() => svc.DoSomethingAsync());
}
[Test]
public
async Task
SecondTest()
{
var svc = Mock.Create<TestAsyncService>();
Mock.Arrange(() => svc.DoSomethingAsync()).Returns(Task.Run(() => { }));
await svc.DoSomethingAsync();
Mock.Assert(() => svc.DoSomethingAsync());
}
}
public
interface
TestAsyncService
{
Task DoSomethingAsync();
}
With the latest version of JustMock on nuget (2013.2.522), this fails the second test consistently. However, if you roll back to an older version of (2013.1.507), it works.
I've tried this with both Xunit and Nunit, same thing happens.
0
Hi Isaac,
Thank you for reporting the issue.
We managed to reproduce and fix this. It was a race issue in the free version of JustMock. However, the fix will be included in the next official release.
P.S. For reporting this bug, we have granted you some Telerik points.
Regards,
Kaloyan
Telerik
Thank you for reporting the issue.
We managed to reproduce and fix this. It was a race issue in the free version of JustMock. However, the fix will be included in the next official release.
P.S. For reporting this bug, we have granted you some Telerik points.
Regards,
Kaloyan
Telerik
0
Isaac Abraham
Top achievements
Rank 1
answered on 18 Jun 2013, 04:23 PM
Another similar issue I have found is that if you sequential mocking does not appear to be threadsafe i.e. if you set a mocked method to return true the first call and false the second, and fire off two calls to that on different threads, there is a chance that you will get true on both calls.
0
Hi Isaac,
Thank you for reporting this. We managed to reproduce it on our side and indeed it appears there is a bug in JustMock. We added it into our backlog and a fix should be shipped with the next official JustMock release.
I hope this works for you.
P.S. For reporting the issue, we have granted you some Telerik points.
Regards,
Kaloyan
Telerik
Thank you for reporting this. We managed to reproduce it on our side and indeed it appears there is a bug in JustMock. We added it into our backlog and a fix should be shipped with the next official JustMock release.
I hope this works for you.
P.S. For reporting the issue, we have granted you some Telerik points.
Regards,
Kaloyan
Telerik
0
Isaac Abraham
Top achievements
Rank 1
answered on 01 Aug 2013, 09:49 AM
Is this EVER going to be fixed? Come on guys. Here's a really, REALLY basic example of how the latest version JML (2013.2.611.0) is not threadsafe: -
This fails every time.
Seriously - if this sort of thing is not something I can rely on JM for, let me know and I can look at moving over to a different mocking framework - not a problem.
public
class
TestClass
{
[Fact]
public
void
TestMethod()
{
var generator = Mock.Create<GuidGenerator>();
var lotsOfGuids = Enumerable.Range(0, 10000)
.AsParallel()
.Select(x => generator.Generate())
.ToArray();
// BOOM!
}
}
public
interface
GuidGenerator
{
Guid Generate();
}
This fails every time.
Seriously - if this sort of thing is not something I can rely on JM for, let me know and I can look at moving over to a different mocking framework - not a problem.
0
Hi Isaac,
Thanks for reporting this bug. I fixed it now. It was just a misplaced [ThreadStatic] attribute. The fix will be made available in the next internal build.
You can rely on us to continuously improve JustMock and in particular JustMock's suitability for asynchronous and parallel tests.
As a token of gratitude for reporting this bug I gave you some Telerik points.
Have a nice day!
Stefan
Telerik
Thanks for reporting this bug. I fixed it now. It was just a misplaced [ThreadStatic] attribute. The fix will be made available in the next internal build.
You can rely on us to continuously improve JustMock and in particular JustMock's suitability for asynchronous and parallel tests.
As a token of gratitude for reporting this bug I gave you some Telerik points.
Have a nice day!
Stefan
Telerik
0
Isaac Abraham
Top achievements
Rank 1
answered on 14 Aug 2013, 09:34 AM
Confirmed fixed - thanks! :-)