Skip to content

Commit a4bd53a

Browse files
committed
Merge pull request google#867 from Martin2112/fixclustertest
Try to mitigate the race condition in the cluster controller test.
2 parents c7287a1 + b1d0f3d commit a4bd53a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

cpp/log/cluster_state_controller_test.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ const char kNodeId3[] = "node3";
3939

4040
class 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

503509
TEST_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

Comments
 (0)