Genessis_1 0 Newbie Poster


I am new to google mock so sorry if you think this is an easy question.
I am currently testing codes for a project.
There are async calls and i am having a hard time checking the sequence of function calls.
I cannot share the codes so I'll just give sample sequence based on logs.

  1. service::start
  2. manager::start
  3. manager::apples //first thread
  4. manager::egg //second thread
  5. service::doSomething
  6. apples::start //async
  7. apples::create_apples //async
  8. eggs::start //async
  9. eggs::create_eggs //async
  10. service::doAnother
  11. eggs::pack_eggs //async
  12. apples::pack_apples //async

I checked google mock CheatSheet:
But i can't get it to work as I wanted to.

sequence_check_mock obj;
mock_obj_ = &obj;
    Sequence s1, s2;

    EXPECT_CALL( *mock_obj_, service_start() ).InSequence( s1, s2 );
    EXPECT_CALL( *mock_obj_, manager_start() ).InSequence( s1, s2 );
    EXPECT_CALL( *mock_obj_, manager_apples() ).InSequence( s1, s2 );
    EXPECT_CALL( *mock_obj_, manager_eggs() ).InSequence( s1, s2 );
    EXPECT_CALL( *mock_obj_, service_doSomething() ).InSequence( s1, s2 );
    EXPECT_CALL( *mock_obj_, apples_start() ).InSequence( s1 );
    EXPECT_CALL( *mock_obj_, apples_create_apples() ).InSequence( s1 );
    EXPECT_CALL( *mock_obj_, eggs_start() ).InSequence( s2 );
    EXPECT_CALL( *mock_obj_, eggs_create_eggs() ).InSequence( s2 ); 
    EXPECT_CALL( *mock_obj_, service_doAnother() ).InSequence( s1, s2 );
    EXPECT_CALL( *mock_obj_, eggs_pack_eggs() ).InSequence( s2 );
    EXPECT_CALL( *mock_obj_, apples_pack_apples() ).InSequence( s1 );

The checking is ok until service_doAnother. But sometimes, service_doAnother is called after eggs_pack_eggs or apples_pack_apples
so the test would fail. Since in the sequence, it is expected that doAnother should be called before.

  1. eggs::pack_eggs //async
  2. apples::pack_apples //async
  3. service::doAnother

Thanks in advance.