Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Basic tests for link protocol messages.

  • Loading branch information...
commit 04170c3a2b1ebc63149abcbd9541e43595a07cd9 1 parent 2c5d0d3
@kr authored
Showing with 45 additions and 2 deletions.
  1. +41 −0 check-sanity.py
  2. +1 −0  prot.c
  3. +3 −2 testhelpers.py
View
41 check-sanity.py
@@ -27,3 +27,44 @@ def test_ping(self):
got_peers = sorted([(x.addr, x.port) for x in response.peers])
exp_peers = sorted((self.cubby.tester_control_info, self.cubby.control_info))
self.assertEqual(got_peers, exp_peers)
+
+class TestMember(TestCase):
+ def setUp(self):
+ self.root_key = b'kkkkkkkkkkkk'
+ self.cubby = cubbyd()
+ self.cubby.control_send(Ping,
+ memcache_port = 0,
+ http_port = 0,
+ root_key = self.root_key,
+ chain_len = 1
+ )
+ self.pong = self.cubby.control_recv()
+
+ def tearDown(self):
+ self.cubby.kill()
+ del self.cubby
+
+
+ def test_link_secondary_last(self):
+ key = bytearray(self.root_key)
+ key[-1] = (key[-1] + 1) % 256
+ self.cubby.control_send(Link,
+ key = key,
+ rank = 1,
+ )
+ response = self.cubby.control_recv()
+ self.assertEqual(type(response), Linked)
+
+ def test_link_primary(self):
+ key = bytearray(self.pong.root_key)
+ key[-1] = (key[-1] + 1) % 256
+ self.cubby.control_send(Link, key = key, rank = 0)
+ response = self.cubby.control_recv()
+ self.assertEqual(type(response), Link)
+ self.assertEqual(response.key, key)
+ self.assertEqual(response.rank, 1)
+
+ self.cubby.control_send(Linked, key = key)
+ response = self.cubby.control_recv()
+ self.assertEqual(type(response), Linked)
+ self.assertEqual(response.key, key)
View
1  prot.c
@@ -33,6 +33,7 @@ prot_outstanding_link_update(arr a, void *item, size_t index)
link_progress prog = item;
if (!prog->peer) {
+ // It's done! Lett the callback know.
prog->cb(prog->manager, prog->key, 0, prog->data);
return 0; // remove it from the list
}
View
5 testhelpers.py
@@ -160,9 +160,10 @@ def udp_recv(self, timeout=5):
assert(addr == (self.addr, self.control_port))
return payload
- def control_send(self, type, **kw):
+ def control_send(self, type, array=(), **kw):
packet = type(type=type.type, **kw)
- self.udp_send(packet.bytes)
+ extra = b''.join([x.bytes for x in array])
+ self.udp_send(packet.bytes + extra)
def control_recv(self):
return unpack_control_packet(self.udp_recv())
Please sign in to comment.
Something went wrong with that request. Please try again.