System.InvalidOperationException : Collection was modified; enumeration operation may not execute.

4 posts, 0 answers
  1. Sreejith
    Sreejith avatar
    2 posts
    Member since:
    Oct 2019

    Posted 11 Oct 2019 Link to this post

    01.
    [Fact]
    02.public void Reconcile_LocationGroupChangedEvent_ReconcileSuccessfully()
    03.{
    04.    using (var container = new MockingContainer<Assignment>(settings))
    05.    {
    06.        //Arrange
    07.        container.Arrange<IFacade>(x =>x.Initialize()).OccursAtMost(1);
    08.                 
    09.        //Act
    10.        container.Instance.Reconcile();
    11. 
    12.        //Assert
    13.        container.AssertAll();
    14.    }
    15.}
    16. 
    17.// Method under test
    18. 
    19.public void Reconcile()
    20.
    21.    Task.Factory.StartNew(() => facade.Initialize());
    22.}

     

    I am getting intermittent errors when running the above Test. It fails so infrequently that I am unable to debug. When it fails, here is what I see in the logs.

    Reconcile_Test [FAIL]
    System.InvalidOperationException : Collection was modified; enumeration operation may not execute.
    Stack Trace:
         at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
         at System.Collections.Generic.Dictionary`2.Enumerator.MoveNext()
         at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
         at System.Linq.Enumerable.<SelectManyIterator>d__23`3.MoveNext()
         at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
         at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
         at Telerik.JustMock.Core.MocksRepository.GetDebugView(Object mock)
         at Telerik.JustMock.DebugView.<>c.<get_CurrentState>b__1_0()
         at Telerik.JustMock.Core.ProfilerInterceptor.GuardInternal[T](Func`1 guardedAction)
         at Telerik.JustMock.DebugView.TraceEvent(IndentLevel traceLevel, Func`1 message)
         at Telerik.JustMock.Core.Context.MockingContext.ResolveRepository(UnresolvedContextBehavior unresolvedContextBehavior)
         at Telerik.JustMock.Helpers.FluentHelper.<>c__DisplayClass13_0`1.<AssertAll>b__0()
         at Telerik.JustMock.Core.ProfilerInterceptor.GuardInternal(Action guardedAction)
         at Telerik.JustMock.AutoMock.MockResolver.ForEachMock(Action`1 action)
         at Telerik.JustMock.Core.ProfilerInterceptor.GuardInternal(Action guardedAction)
      E:\agt01\COM-CN-JOB1\AssignmentTest.cs(14,0): at AssignmentTest.Reconcile_Test()
  2. Ivo
    Admin
    Ivo avatar
    27 posts

    Posted 14 Oct 2019 Link to this post

    Hello Sreejith,

    Most probably the issue is caused by the asynchronous call inside the method under test. I was unable to reproduce such behavior using the code snippet you have sent combined with some assumptions around it. It is not clear enough what exactly is the use case, so I would like to ask you to share more details. Please clarify also, whether the test is failing when it runs in bundle with others or just standalone? As far as I know, xUnit executes tests in parallel, so it could be also a possible source of troubles. It would be nice to share what version of JustMock you are using free or commercial?

    Regards,


    Ivo
    Progress Telerik

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Sreejith
    Sreejith avatar
    2 posts
    Member since:
    Oct 2019

    Posted 14 Oct 2019 in reply to Ivo Link to this post

    Hi Ivo,

    This test is failing intermittently in our build server. There, tests are run sequentially if it is in a single file, but we run different test classes in parallel.

    In my local machine, it is more or less impossible to reproduce.

    I am using JustMock free version 2018.1.117.2

  4. Ivo
    Admin
    Ivo avatar
    27 posts

    Posted 15 Oct 2019 Link to this post

    Hello Sreejith, 

    I am afraid that without stable reproduction it would be hard to identify the root cause of the issue. However, I encourage you to try the latest version, since R1 2018 we have addressed a few fixes regarding multithreading, they could resolve this particular problem too. 

    I hope the provided information helps. Any other relevant information that might help for the reproduction and further investigation is also appreciated.  

    Regards,


    Ivo
    Progress Telerik

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top