Skip to content
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

Callback may not be threadsafe (ID10T error) #651

Closed
bloritsch opened this issue Aug 2, 2018 · 3 comments
Closed

Callback may not be threadsafe (ID10T error) #651

bloritsch opened this issue Aug 2, 2018 · 3 comments

Comments

@bloritsch
Copy link

I'm writing unit tests for a library that generates REST web service clients from an interface. As a result I need to verify the values provided by the HttpRequestMessage while I mock out the HttpClient. My tests are written like this:

mockClient.Setup(m => m.SendAsync(It.IsAny<HttpRequestMessage>())).ReturnsAsync(response)
    .Callback(verifyRequest);

verifyRequest is an Action<HttpRequestMessage> so that I can run my fluent assertions on the provided object. I'm experiencing some strangeness with Moq, and I don't know if its the set up, or what.

I have two classes with tests, so the test runner is running them in parallel. One of my assertions is failing because the HttpRequestMessage instance that was created for one class in the other. It's always the first tests that are getting the cross-talk, and it's always the same test that's failing. However, when I run that test in isolation it passes.

My repository is here: https://github.com/bloritsch/DHaven.Faux/tree/DHaven.Faux-19

I'm at a loss as to explain this. I want to use Moq, but I also need my unit tests to run consistently so I can have full confidence that the generated classes aren't causing problems.

@bloritsch
Copy link
Author

Nevermind. This is a stupid issue on my end. Has to do with how the HttpClient is used. Have to ensure my tests are singlethreaded even though the code itself is threadsafe.

@bloritsch bloritsch changed the title Callback may not be threadsafe Callback may not be threadsafe (ID10T error) Aug 2, 2018
@stakx
Copy link
Contributor

stakx commented Aug 2, 2018

Uhm, shall we close this then? :) Or is there still something in Moq that needs to be looked at?

@bloritsch
Copy link
Author

By all means. I couldn't find the close button last night.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants