title: Test asynchronous call via google tests
body: <p>I have a class Communicator that tests whether it can connect the test server. Here is how I call it:
  </p>
  
  <pre><code>class CommunicatorTest
  {
  public:
      CommunicatorTest() {}
      bool doTest()
      {
          bool _success;
          Parameters params;
          Communicator communicator;
          communicator.connect(params, [this, &amp;_success](bool success)
          {
              statusCode = errorCode;
              m_condition.notify_one();
          });
  
          std::unique_lock&lt;std::mutex&gt; uGuard(m_mutex);
          m_condition.wait(uGuard);
          return _success;
      }
  
  private:
      std::mutex m_mutex;
      std::condition_variable m_condition;
  };
  
  bool communicatorTest()
  {
      CommunicatorTest test;
      bool success = test.doTest();
      return success;
  }
  
  TEST(CommunicatorTest, test_eq)
  {
      EXPECT_EQ(communicatorTest(), true);
  }
  </code></pre>
  
  <p>I tried to use condition and mutex to make this code synchronous but it fails, the logs say only that test was running and immediately finishes.</p>
  
  <p>Is there a way to test success variable from the callback using google tests? 
  Thanks in advance.</p>