C++ Google test aborts on Ubuntu calling Notify() multiple times on Notification object

241 views Asked by At

i use google test and google mock. There is a mock object on which i expect a method call OnConnectionError() which notifies the absl::Notification object done 3 times.

  absl::Notification done;
  EXPECT_CALL(*client, OnConnectionError(::testing::_)).Times(3)
    .WillRepeatedly(Notify(&done));

  bool result = client->ConnectToServer("localhost", 5000, 2);

  done.WaitForNotificationWithTimeout(absl::Duration(absl::Seconds(30)));

The method client->ConnectToServer has a loop which results in the repetitive call of OnConnectionError, which is fully fine and the desired behaviour.

On Windows the unit test passes fine. When jenkins runs it on ubuntu, it aborts the whole test run (not only failing one test!!) with the following output.

[notification.cc : 32] RAW: Notify() method called more than once for Notification object 0x7ffffde87320

Is it not allowed to call the Notification object multiple times? Why does the test success on Windows and aborts on ubuntu?

many thanks for your support!

1

There are 1 answers

0
Rene Lorenz On BEST ANSWER

I found the answer by my self: I reviewed the relevant source of google abseil. In notification.cc i found the relevant error message. The respective source part is surrounded by a

#ifndef NDEBUG

I edited the CMakeLists file in order to rebuild it in Release mode by adding the line set(CMAKE_BUILD_TYPE Release), so the NDEBUG flag is defined on compile time.

As a consequence not directly connected to this issue, i refactored the code under test in a way, to avoid the loop, which notifies the absl::Notification object multiple times, since this issue showed me that there is a demand for improving the code.