-
-
Notifications
You must be signed in to change notification settings - Fork 802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
4.1 does not support multi-threading #62
Comments
I agree with DanTup, this is a real pain as we have tests that use threads to test a wrapper around something is none blocking, this something is mocked and the test is now failing as the mock itself is doing the blocking. |
Would be great if you guys could put together a PR with a fix that satisfies both bug reports: the one that the mocks break when accessed from multiple threads, and the one where you want to actually lock outside. Maybe there's a new property on the mock like new Mock { ThreadSafe = false } or the like? |
Making the lock optional would be a very easy fix, and we can keep using the existing tests for issue 249 and added the reverse test for this fix. But. It does seem like an easy way out! Reading the original bug on Google Code (http://code.google.com/p/moq/issues/detail?id=249) it seems that the problems were all caused by the concurrent access to the ActualInvocations in the AddActualInvocation interception strategy. Adding a lock specifically to that fixes all the repo cases I've found. Looking around the code it seems that there are other things in the interceptors that should be locked, mostly on the InterceptStrategyContext object. SO my question is, do we want to add the ThreadSafe option to the mock, which essentially blocks mutlithreaded tests unless we enable it and accept that it has a potential to crash. OR do you think trying to sort out the underlying problem is a better course of action? I'm unsure as this is my first time looking at Moq's code base. |
In all honesty, I thought the previous PR had fixed the issue for good. So I'm all for making it work as it should, and support both scenarios I'm very greateful for taking a closer look at this issue. I've been lucky Thanks in advance for any effort you can put on it, /kzu /kzu Daniel Cazzulino On Tue, Dec 10, 2013 at 7:06 AM, MatKubicki [email protected]:
|
The fix for this issue also fixes issue #47. I have used the test case from issue 47, with a bit of modification, as a test case for my new code. I have removed the test case added for issue 249 as that was explicitly checking the reverse case, that mocks we're not multi-threaded. All I need to do now is work out how to commit this code to GitHub without it reporting every file as changed. I imagined it was a line feed/ carriage return issue but the files that I have changed appear fine. I am trying to use the core.autocrlf option set to true, but the behavior seemed the same with it set to false as well. I may just give up and make my commits via the website! |
Ok i've added a pull request #68. Hope I've done this right, if not then please let me know where i've gone wrong, I'm new to Git and Github! |
Sorry for the lack of responses; taken me a while to catch up! I've had a quick scan through the PR; there's a lot of changes in there - would using a ConcurrentDictionary not be better than all the locks for invocationLists? (assuming you're building in a version of .NET that contains them) (Added this comment to the PR; guess it makes more sense there; though don't mistake me for someone of authority, I'm just a user!) |
I think Moq is planning to continue support for 3.5, I certainly hope it is as we're stuck with it here for a while longer! I did start writing with the ConcurrentDictionary at first, but reverted once I remembered that. |
Ah, makes sense. Doh! |
I scanned the PR and it looks good. I like the cleanup you've done too, I'd like to get more feedback on the fix so that we all agree this is the Looping moqdisc for that purpose /kzu Daniel Cazzulino On Wed, Dec 11, 2013 at 11:00 AM, MatKubicki [email protected]:
|
I can try and run our tests with it; that reliably fail in the latest release (we had to roll back); but it's not likely to be this week due to some fire-fighting :( |
Fixing #62 - Multithreaded test not working
I've got another example of Moq failing when run parallel. I finally managed to simplify a flaky test down to the following code. When run in single-threaded mode (1 degree of parallelism), it works. Anything more [on a multi-core machine] and it fails. I've cloned the Moq source and rebuilt as of today.
|
Of by fail you mean fails the test them that would make sense as moq will be returning the wrong value from AddTwo when run in parallel. Is be interested to know if this fails with my PR, I would guess not. I'll try for myself on my return to the office on Thursday. |
That would be awesome Matthew! /kzu from mobile
|
This is now fixed with my PR that i've added for #78, I seem to have mucked up somewhere when it comes to adding that PR as it has instead appeared as its own issue, #80. Either way the latest code from @JeffAtDeere is pretty much the same as the test case from #78 and both are fixed by #80's PR! On second glance I see that its fine, and just my lack of familiarity with Github, the PR #80 fixes all. |
Apologies for the delay... I tested both the latest NuGet package (which had the first set of changes in) and the latest code from @MatKubicki's repo, and both versions result in our concurrency tests passing (which were previously failing due to the locks causing them to run one after the other). I haven't reviewed the code; but it definitely seems to fix the regression I was reporting in this case 👍 |
Great. Will ship a new version today /kzu from mobile
|
It seems the "fix" for some race conditions in 4.0 was to put locks around mocks internally. This breaks any tests that were using mocks in a multi-threaded way (we've had to roll back to 4.0 for our concurrency tests to work).
If the default is going to be that a mock is not thread-safe, there should at least be some way of opting in to a thread-safe mock. Despite the other issues raised in 4.0, our tests were 100% reliable; but in 4.1 they're 100% broken; so this seems to be a big breaking change in terms of functionality 👎
The text was updated successfully, but these errors were encountered: