title: How to make a ROS publish/subscribe unit test deterministic?
body: <p>I create a publisher and a subscriber, publish a message, then check if the callback has fired. The check actually fails unless I spin for some hundreds of cycles after publishing. How do I make the unit test deterministic?</p>
  
  <pre class="lang-cpp prettyprint-override"><code>bool called_back = false;
  Publisher  p = node.advertise(topic, 1);
  Subscriber s = node.subscribe(topic, 1, [&amp;]{ called_back = true; })
  
  p.publish();
  for (int i = 0; i != 1000; ++i)
    ros::spinOnce();
  ASSERT_TRUE(called_back);
  </code></pre>