Giter Club home page Giter Club logo

Comments (10)

kzu avatar kzu commented on July 29, 2024

@alextercete or @Blewzman: do you have an idea of what the issue might be?

from moq4.

alextercete avatar alextercete commented on July 29, 2024

@mmajcica, are GetSortCriteriaFromCache and GetFilterCriteriaFromCache async? I mean, do they return Task or Task<>?

from moq4.

mmajcica avatar mmajcica commented on July 29, 2024

@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.

mmajcica avatar mmajcica commented on July 29, 2024

This evening I will try to replicate with a small example and come back with more details.

from moq4.

alextercete avatar alextercete commented on July 29, 2024

@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.

kzu avatar kzu commented on July 29, 2024

@MatKubicki you think this might be related?

from moq4.

MatKubicki avatar MatKubicki commented on July 29, 2024

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.

kzu avatar kzu commented on July 29, 2024

Thanks for taking the time to look at this issue @MatKubicki !

from moq4.

MatKubicki avatar MatKubicki commented on July 29, 2024

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.

mmajcica avatar mmajcica commented on July 29, 2024

@danielkzu When will this be available via NuGet?

Thanks

from moq4.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.