jonreid / OCMockito

Mockito for Objective-C: creation, verification and stubbing of mock objects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OCMockito thread/queue safety

RockLobster opened this issue · comments

I noticed that all mock objects use a shared MKTMockingProgress object.
Every once in a while the tests crash when MKTMockingProgress's ongoingStubbing property is being set because the old value gets double released.
This seems to happen when the object under test dispatches to a different queue than it received a request from.

A simple solution is to override the setter with:

- (void)setOngoingStubbing:(MKTOngoingStubbing *)ongoingStubbing
{
    @synchronized (self)
    {
        _ongoingStubbing = ongoingStubbing;
    }
}

since we included this change, we haven't encountered the crash anymore.

Included in 71df245. Thank you!