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)
- Mock verification slow with It.Is(Expression) HOT 5
- [Feature Request] Make it possible to moq concrete classes HOT 1
- Moq dependency uprev is not working as expected HOT 1
- SponsorLink Integration Makes Moq Unuasable due to PII and GDPR Requirements HOT 9
- Add the ability to compare ref argument by value HOT 1
- Cannot cast inside the Action<T> parameter of Verify method
- Wrong Setup by using String interpolation within It.Is<string> HOT 4
- Question: would it make sense to call verify all on a strict mock when the mock gets disposed?
- `DefaultValueProvider` extensibility
- Some source code files is filled with comments like: "Unmerged change from project "
- Exception throw in dotnet8 (working in dotnet6) HOT 2
- VerifySet throws TargetInvocationException when constructer refers to itself
- Add ability for asynchronously waiting for an invocation
- 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
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.