@@ -39,6 +39,10 @@ const char kNodeId3[] = "node3";
3939
4040class ClusterStateControllerTest : public ::testing::Test {
4141 public:
42+ // TODO: Some of the tests in this class rely on sleep() calls.
43+ // Ideally they should be waiting for defined conditions to avoid timing
44+ // races.
45+
4246 // TODO(pphaneuf): The size of the thread pool is a bit of a magic
4347 // number... We have some callbacks that block, so it has to be "at
4448 // least this" (so we're setting it explicitly, in case your machine
@@ -99,6 +103,8 @@ class ClusterStateControllerTest : public ::testing::Test {
99103 return controller_.local_node_state_ ;
100104 }
101105
106+ // TODO: This should probably return a util::StatusOr<ClusterNodeState>
107+ // rather than failing a CHECK if absent.
102108 ct::ClusterNodeState GetNodeStateView (const string& node_id) {
103109 auto it (controller_.all_peers_ .find (" /nodes/" + node_id));
104110 CHECK (it != controller_.all_peers_ .end ());
@@ -501,6 +507,16 @@ TEST_F(ClusterStateControllerTest, TestGetLocalNodeState) {
501507
502508
503509TEST_F (ClusterStateControllerTest, TestNodeHostPort) {
510+ // Allow some time for our view of the node state to stabilize and then
511+ // check that it has. Ideally we would wait for this to definitely happen
512+ // but there seems to be no easy way to arrange this.
513+ sleep (1 );
514+ const ClusterNodeState orig_node_state (GetNodeStateView (kNodeId1 ));
515+ EXPECT_EQ (kNodeId1 , orig_node_state.hostname ());
516+ EXPECT_EQ (9001 , orig_node_state.log_port ());
517+
518+ // Now try to change the state and again allow some time for our view
519+ // to update
504520 const string kHost (" myhostname" );
505521 const int kPort (9999 );
506522
0 commit comments