Comments (10)
@alextercete or @Blewzman: do you have an idea of what the issue might be?
from moq4.
@mmajcica, are GetSortCriteriaFromCache
and GetFilterCriteriaFromCache
async? I mean, do they return Task
or Task<>
?
from moq4.
@alextercete This is the signature of both of the methods.
SortCriteria GetSortCriteriaFromCache(string cacheKey);
FilterCriteria GetFilterCriteriaFromCache(string cacheKey, FlowType? flowType = null);
Seems that issue is due to the fact that moq in this version treats the threads in a different way.
Test didin't changed and if I revert the mock to 4.0 it is green.
from moq4.
This evening I will try to replicate with a small example and come back with more details.
from moq4.
@danielkzu, I think the issue here is not related to the recent async improvements in Moq. It might be related to #68 though.
from moq4.
@MatKubicki you think this might be related?
from moq4.
I've tried what I assume is a set of tests similiar to the code mmajcica has and it fails in the way reported. And when I add the lock in the Interceptor that was removed for #68 it passes.
So this seems to be a problem with handling the setups when they are run in multiple threads. I will see if I will have a look at sorting this out, although this is my last day working.
For reference this test seems to replicate the issue:
public interface IInterfaceOne
{
ResultOne GetResultOne(string cacheKey);
ResultTwo GetResultTwo(string cacheKey, int? otherKey = null);
}
public class ResultOne
{
}
public class ResultTwo
{
}
public class TestOne
{
public void TestMethod(IInterfaceOne intOne, string key)
{
Task<ResultTwo> getResultTwoTask = Task<ResultTwo>.Factory.StartNew(() => intOne.GetResultTwo(key));
Task<ResultOne> getResultOneTask = Task<ResultOne>.Factory.StartNew(() => intOne.GetResultOne(key));
ResultTwo filterCriteria = getResultTwoTask.Result;
ResultOne sortCriteria = getResultOneTask.Result;
}
}
public class TestCase
{
[Fact()]
public void DoTest()
{
Mock<IInterfaceOne> m = new Mock<IInterfaceOne>();
ResultOne expectedResOne = new ResultOne();
ResultTwo expectedResTwo = new ResultTwo();
m.Setup(it => it.GetResultTwo("Test", null)).Returns(expectedResTwo);
m.Setup(it => it.GetResultOne("Test")).Returns(expectedResOne);
TestOne t = new TestOne();
t.TestMethod(m.Object, "Test");
m.VerifyAll();
}
}
from moq4.
Thanks for taking the time to look at this issue @MatKubicki !
from moq4.
On the above PR, I had a few go's at fixing this problem. The root of it is that the CurrentCall property on the InterceptorStrategyContext was being set on multiple threads and then used later on, what I needed to add was a CurrentCall property for each thread working through Interceptor.Intercept. In the PR I've done this by splitting the InterceptorStrategyContext into a class used by all intercepts (InterceptorContext) and a class used by each thread in Intercept (CurrentInterceptContext).
The only thing on CurrentInterceptContext is the CurrentCall, I did try removing that entirely from the context as it can easily be pulled from the ordered calls list, I made the code in ExtractProxyCall to do this shared and this worked for all but one case.
This case was the MockSequence tests where getting the CurrentCall more than once resulted in incorrect behaviour and MockSequenceFixture.NoCyclicSequenceFail and CyclicSequenceSuccesss failing. The problem was checking the status of a Condition changes the sequence number, so checking more than once changes behaviour, there is a note in the original code indicating this slightly hacky nature! See MockSequence.For for this comment, I didn't have time to start tearing apart this code as well as the interceptor, so have gone with the easier fix described. If someone who knows their way around wants to take a shot over Christmas then go for it!
Hope this rambling was of use,
TL;DR; Problem's fixed but in the easiest way, some old code could be fixed to make the fix neater!
from moq4.
@danielkzu When will this be available via NuGet?
Thanks
from moq4.
Related Issues (20)
- Moq library throwing TypeIniatilizationException. HOT 1
- Request: Ability to setup a property of type Task<ConcreteType> by mocking interface
- Supporting .NET8 HOT 2
- Mock.Protected().Verify fails sometimes
- Moq "set" matcher fails when setting StringValues with string HOT 1
- It.IsAny<StructObject>() isn't
- Documentation Unavailable Online HOT 2
- Consider adding IgnoresAccessChecksTo("Unsupported")
- Explicit support for matching cancellation tokens with It class. (It.IsCancellationToken())
- Moq Setup does not work with "object" as generic type? HOT 1
- IVerifies.Verifiable* documentation comments errata?
- Support for post-invocation callbacks on void methods?
- Semantic error in unit test MatchesIsNotInEnumerable()?
- Documentation link is broken HOT 9
- Constructing Mock<DerivedControl>.Object throws TypeLoadException HOT 2
- How do you Verify an IAsyncEnumerable<T> ?
- Add Way to Exclude Calls from VerifyNoOtherCalls HOT 1
- mock.Protected().Verify() does not work correctly HOT 2
- Constructor arguments should be nullable
- Documentation link gives 404 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moq4.