chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
Code under test spawns a new thread which returns done through this...

           
 _mainThreadDispatcher.BeginInvoke(DispatcherPriority.Normal,
              (ThreadStart)delegate()
              {
                  if (Done != null)
                  {
                      Done(this, new MyEventArgs());
                  }
              });


In the test I subscribe to this Done event. The test code gets to this point, but not sure where BeginInvoke ends up. It will never get to the if(Done...

The code under usage works fine running normally.
Is there any expected issue with trying to return control back like this when under test?
thanks! :D
asked by etropic (1.8k points)

5 Answers

0 votes
As far as we know there are no issues related to Isolator and the scenario you've described.

What version of Isolator are you using?
Can you post the test code as well?
answered by dhelper (11.9k points)
0 votes
Isolator 5.4.2.0

        [TestMethod(), Isolated]
        public void Reset_Test()
        {
            _Code.Done += new Code.DoneEventHandler (TestDone);

            _TestTrigger = new AutoResetEvent(false);

            _TestTrigger.Reset();

            _Code.Reset();

            _TestTrigger.WaitOne();
       
            _Code.Done -= TestDone;
        }

       void TestDone(Object o, EventArgs args)
      {
             _TestTrigger.Set();
      }



_Code.Reset() calls a method that spawns a new thread. This new thread then ends with

          
 _mainThreadDispatcher.BeginInvoke(DispatcherPriority.Normal, 
              (ThreadStart)delegate() 
              { 
                  if (Done != null) 
                  { 
                      Done(this, new MyEventArgs()); 
                  } 
              });


When processing gets here, I can see that Done has the correct handler on it from the test. But control returns to the test seemingly without actually calling the handler. So the test spins in WaitOne()
answered by etropic (1.8k points)
0 votes
Hi,

I would like to verify something. I see that in the test you posted there is no Isolator dependency besides Isolated attribute. Can you run the test with Isolator disabled? (In Visual-Studio, Typemock -> Disable Typemock Isolator).

I would like to know if it reproduces the same way when Isolator disabled.

Regards,
Elisha
Typemock Support
answered by Elisha (12k points)
0 votes
I actually added the Isolated on the method level in case it was part of the issue. I usually run with Isolated on the class level.

Just went back and removed both Isolated. Same result.
The constructor for the class under test takes other objects that are Isolate.Fake... but your right, otherwise there is no Isolator code in the test method.

Looking at the thread name while in the RaiseDone() it says...
Agent: adapter run thread for test 'Reset_Test' with id '03415223-60ae-4e5a-9bd5-c9237e638df9
which is the same name that the thread from the test class reports.

Thanks for your time! Any other advice would be appreciated!
(I suppose i have a different mock framework that might work for this test, I could try it just to know for sure if it is a isolator problem, or something with the test framework maybe? (or my code of course!))
answered by etropic (1.8k points)
0 votes
UPDATE:

Indeed this is the fault of my code. I think the test code misused the AutoResetEvent signal.

Changing it a bit confirms that Isolator seems to be handling all the different threads correctly.

Thanks for your time!
answered by etropic (1.8k points)
...