-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathJobIDTest.cpp
More file actions
93 lines (74 loc) · 2.79 KB
/
JobIDTest.cpp
File metadata and controls
93 lines (74 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <libstuff/SData.h>
#include <test/clustertest/BedrockClusterTester.h>
struct JobIDTest : tpunit::TestFixture {
JobIDTest()
: tpunit::TestFixture("JobID",
BEFORE_CLASS(JobIDTest::setup),
AFTER_CLASS(JobIDTest::teardown),
TEST(JobIDTest::test)
) { }
BedrockClusterTester* tester;
void setup () {
tester = new BedrockClusterTester();
}
void teardown () {
delete tester;
}
void test()
{
BedrockTester& leader = tester->getTester(0);
BedrockTester& follower = tester->getTester(1);
// Create a job in leader
SData createCmd("CreateJob");
createCmd["name"] = "TestJob";
STable response = leader.executeWaitVerifyContentTable(createCmd);
// Restart follower. This is a regression test, before we only re-initialized the lastID if it was !=0 which made
// these tests pass (because the first ID is 0) but fail in the real life. So here we make sure that when a follower
// becomes leader, it gets the correct ID and the inserts do not fail the unique constrain due to repeated ID.
tester->stopNode(1);
tester->startNode(1);
// Stop leader
tester->stopNode(0);
int count = 0;
bool success = false;
while (count++ < 50) {
SData cmd("Status");
string response = follower.executeWaitVerifyContent(cmd);
STable json = SParseJSONObject(response);
if (json["isLeader"] == "true") {
success = true;
break;
}
// Give it another second...
sleep(1);
}
// Make sure it actually succeeded.
ASSERT_TRUE(success);
// Create a job in the follower
response = follower.executeWaitVerifyContentTable(createCmd, "200");
// Restart leader
tester->startNode(0);
count = 0;
success = false;
while (count++ < 50) {
SData cmd("Status");
string response = leader.executeWaitVerifyContent(cmd);
STable json = SParseJSONObject(response);
if (json["isLeader"] == "true") {
success = true;
break;
}
// Give it another second...
sleep(1);
}
// Make sure it also succeeded.
ASSERT_TRUE(success);
// Create a new job in leader.
response = leader.executeWaitVerifyContentTable(createCmd);
// Get the 3 jobs to leave the db clean
SData getCmd("GetJobs");
getCmd["name"] = "*";
getCmd["numResults"] = 3;
follower.executeWaitVerifyContentTable(getCmd, "200");
}
} __JobIDTest;