1
0
Fork 0

Merge pull request #712 from rqlite/e2e-join

End-to-end test of idempotent join
master
Philip O'Toole 4 years ago committed by GitHub
commit 4269afcad0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -104,6 +104,7 @@ const (
numQueries = "queries" numQueries = "queries"
numBackups = "backups" numBackups = "backups"
numLoad = "loads" numLoad = "loads"
numJoins = "joins"
// PermAll means all actions permitted. // PermAll means all actions permitted.
PermAll = "all" PermAll = "all"
@ -131,6 +132,8 @@ func init() {
stats.Add(numExecutions, 0) stats.Add(numExecutions, 0)
stats.Add(numQueries, 0) stats.Add(numQueries, 0)
stats.Add(numBackups, 0) stats.Add(numBackups, 0)
stats.Add(numLoad, 0)
stats.Add(numJoins, 0)
} }
// SetTime sets the Time attribute of the response. This way it will be present // SetTime sets the Time attribute of the response. This way it will be present
@ -251,6 +254,7 @@ func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) {
stats.Add(numLoad, 1) stats.Add(numLoad, 1)
s.handleLoad(w, r) s.handleLoad(w, r)
case strings.HasPrefix(r.URL.Path, "/join"): case strings.HasPrefix(r.URL.Path, "/join"):
stats.Add(numJoins, 1)
s.handleJoin(w, r) s.handleJoin(w, r)
case strings.HasPrefix(r.URL.Path, "/remove"): case strings.HasPrefix(r.URL.Path, "/remove"):
s.handleRemove(w, r) s.handleRemove(w, r)

@ -163,6 +163,9 @@ class Node(object):
def num_snapshots(self): def num_snapshots(self):
return int(self.expvar()['store']['num_snapshots']) return int(self.expvar()['store']['num_snapshots'])
def num_join_requests(self):
return int(self.expvar()['http']['joins'])
def wait_for_applied_index(self, index, timeout=TIMEOUT): def wait_for_applied_index(self, index, timeout=TIMEOUT):
t = 0 t = 0
while self.applied_index() < index: while self.applied_index() < index:
@ -352,6 +355,29 @@ class TestSingleNode(unittest.TestCase):
time.sleep(1) time.sleep(1)
t+=1 t+=1
class TestIdempotentJoin(unittest.TestCase):
def tearDown(self):
deprovision_node(self.n0)
deprovision_node(self.n1)
def test(self):
self.n0 = Node(RQLITED_PATH, '0')
self.n0.start()
self.n0.wait_for_leader()
self.n1 = Node(RQLITED_PATH, '1')
self.n1.start(join=self.n0.APIAddr())
self.n1.wait_for_leader()
self.assertEqual(self.n0.num_join_requests(), 1)
# Restart n1, and ensure it doesn't make a second join request
# since it's already part of the cluster.
self.n1.stop()
self.n1.start(join=self.n0.APIAddr())
self.n1.wait_for_leader()
self.assertEqual(self.n0.num_join_requests(), 1)
class TestEndToEnd(unittest.TestCase): class TestEndToEnd(unittest.TestCase):
def setUp(self): def setUp(self):
n0 = Node(RQLITED_PATH, '0') n0 = Node(RQLITED_PATH, '0')

Loading…
Cancel
Save