remove old tests
This commit is contained in:
parent
0a14901e94
commit
ce06d379d9
|
@ -729,241 +729,6 @@ class WebSocketAPI(ServerBase, unittest.TestCase):
|
|||
self.assertEqual(err[u"error"], u"must open mailbox before closing")
|
||||
|
||||
|
||||
@inlineCallbacks
|
||||
def OFFtest_allocate_1(self):
|
||||
c1 = yield self.make_client()
|
||||
msg = yield c1.next_non_ack()
|
||||
self.check_welcome(msg)
|
||||
c1.send(u"bind", appid=u"appid", side=u"side")
|
||||
yield c1.sync()
|
||||
self.assertEqual(list(self._rendezvous._apps.keys()), [u"appid"])
|
||||
app = self._rendezvous.get_app(u"appid")
|
||||
self.assertEqual(app.get_claimed(), set())
|
||||
c1.send(u"list")
|
||||
msg = yield c1.next_non_ack()
|
||||
self.assertEqual(msg["type"], u"channelids")
|
||||
self.assertEqual(msg["channelids"], [])
|
||||
|
||||
c1.send(u"allocate")
|
||||
msg = yield c1.next_non_ack()
|
||||
self.assertEqual(msg["type"], u"allocated")
|
||||
cid = msg["channelid"]
|
||||
self.failUnlessIsInstance(cid, type(u""))
|
||||
self.assertEqual(app.get_claimed(), set([cid]))
|
||||
channel = app.get_channel(cid)
|
||||
self.assertEqual(channel.get_messages(), [])
|
||||
|
||||
c1.send(u"list")
|
||||
msg = yield c1.next_non_ack()
|
||||
self.assertEqual(msg["type"], u"channelids")
|
||||
self.assertEqual(msg["channelids"], [cid])
|
||||
|
||||
c1.send(u"release", channelid=cid)
|
||||
msg = yield c1.next_non_ack()
|
||||
self.assertEqual(msg["type"], u"released")
|
||||
self.assertEqual(msg["status"], u"deleted")
|
||||
self.assertEqual(app.get_claimed(), set())
|
||||
|
||||
c1.send(u"list")
|
||||
msg = yield c1.next_non_ack()
|
||||
self.assertEqual(msg["type"], u"channelids")
|
||||
self.assertEqual(msg["channelids"], [])
|
||||
|
||||
@inlineCallbacks
|
||||
def OFFtest_allocate_2(self):
|
||||
c1 = yield self.make_client()
|
||||
msg = yield c1.next_non_ack()
|
||||
self.check_welcome(msg)
|
||||
c1.send(u"bind", appid=u"appid", side=u"side")
|
||||
yield c1.sync()
|
||||
app = self._rendezvous.get_app(u"appid")
|
||||
self.assertEqual(app.get_claimed(), set())
|
||||
c1.send(u"allocate")
|
||||
msg = yield c1.next_non_ack()
|
||||
self.assertEqual(msg["type"], u"allocated")
|
||||
cid = msg["channelid"]
|
||||
self.failUnlessIsInstance(cid, type(u""))
|
||||
self.assertEqual(app.get_claimed(), set([cid]))
|
||||
channel = app.get_channel(cid)
|
||||
self.assertEqual(channel.get_messages(), [])
|
||||
|
||||
# second caller increases the number of known sides to 2
|
||||
c2 = yield self.make_client()
|
||||
msg = yield c2.next_non_ack()
|
||||
self.check_welcome(msg)
|
||||
c2.send(u"bind", appid=u"appid", side=u"side-2")
|
||||
c2.send(u"claim", channelid=cid)
|
||||
c2.send(u"add", channelid=cid, phase="1", body="")
|
||||
yield c2.sync()
|
||||
|
||||
self.assertEqual(app.get_claimed(), set([cid]))
|
||||
self.assertEqual(strip_messages(channel.get_messages()),
|
||||
[{"phase": "1", "body": ""}])
|
||||
|
||||
c1.send(u"list")
|
||||
msg = yield c1.next_non_ack()
|
||||
self.assertEqual(msg["type"], u"channelids")
|
||||
self.assertEqual(msg["channelids"], [cid])
|
||||
|
||||
c2.send(u"list")
|
||||
msg = yield c2.next_non_ack()
|
||||
self.assertEqual(msg["type"], u"channelids")
|
||||
self.assertEqual(msg["channelids"], [cid])
|
||||
|
||||
c1.send(u"release", channelid=cid)
|
||||
msg = yield c1.next_non_ack()
|
||||
self.assertEqual(msg["type"], u"released")
|
||||
self.assertEqual(msg["status"], u"waiting")
|
||||
|
||||
c2.send(u"release", channelid=cid)
|
||||
msg = yield c2.next_non_ack()
|
||||
self.assertEqual(msg["type"], u"released")
|
||||
self.assertEqual(msg["status"], u"deleted")
|
||||
|
||||
c2.send(u"list")
|
||||
msg = yield c2.next_non_ack()
|
||||
self.assertEqual(msg["type"], u"channelids")
|
||||
self.assertEqual(msg["channelids"], [])
|
||||
|
||||
@inlineCallbacks
|
||||
def OFFtest_allocate_and_claim(self):
|
||||
r = self._rendezvous.get_app(u"appid")
|
||||
c1 = yield self.make_client()
|
||||
msg = yield c1.next_non_ack()
|
||||
self.check_welcome(msg)
|
||||
c1.send(u"bind", appid=u"appid", side=u"side")
|
||||
c1.send(u"allocate")
|
||||
msg = yield c1.next_non_ack()
|
||||
self.assertEqual(msg["type"], u"allocated")
|
||||
cid = msg["channelid"]
|
||||
c1.send(u"claim", channelid=cid)
|
||||
yield c1.sync()
|
||||
# there should no error
|
||||
self.assertEqual(c1.errors, [])
|
||||
self.assertEqual(r.get_claimed(), set([cid]))
|
||||
|
||||
# but trying to allocate twice is an error
|
||||
c1.send(u"allocate")
|
||||
yield c1.sync()
|
||||
self.assertEqual(len(c1.errors), 1)
|
||||
self.assertEqual(c1.errors[0]["error"],
|
||||
"You already allocated one channel, don't be greedy")
|
||||
self.assertEqual(r.get_claimed(), set([cid]))
|
||||
|
||||
@inlineCallbacks
|
||||
def OFFtest_allocate_and_claim_two(self):
|
||||
r = self._rendezvous.get_app(u"appid")
|
||||
c1 = yield self.make_client()
|
||||
msg = yield c1.next_non_ack()
|
||||
self.check_welcome(msg)
|
||||
c1.send(u"bind", appid=u"appid", side=u"side")
|
||||
c1.send(u"allocate")
|
||||
msg = yield c1.next_non_ack()
|
||||
self.assertEqual(msg["type"], u"allocated")
|
||||
cid = msg["channelid"]
|
||||
c1.send(u"claim", channelid=cid)
|
||||
yield c1.sync()
|
||||
# there should no error
|
||||
self.assertEqual(c1.errors, [])
|
||||
|
||||
c1.send(u"claim", channelid=u"other")
|
||||
yield c1.sync()
|
||||
self.assertEqual(c1.errors, [])
|
||||
self.assertEqual(r.get_claimed(), set([cid, u"other"]))
|
||||
|
||||
c1.send(u"release", channelid=cid)
|
||||
yield c1.sync()
|
||||
self.assertEqual(r.get_claimed(), set([u"other"]))
|
||||
c1.send(u"release", channelid="other")
|
||||
yield c1.sync()
|
||||
self.assertEqual(r.get_claimed(), set())
|
||||
|
||||
@inlineCallbacks
|
||||
def OFFtest_message(self):
|
||||
c1 = yield self.make_client()
|
||||
msg = yield c1.next_non_ack()
|
||||
self.check_welcome(msg)
|
||||
c1.send(u"bind", appid=u"appid", side=u"side")
|
||||
c1.send(u"allocate")
|
||||
msg = yield c1.next_non_ack()
|
||||
self.assertEqual(msg["type"], u"allocated")
|
||||
cid = msg["channelid"]
|
||||
app = self._rendezvous.get_app(u"appid")
|
||||
channel = app.get_channel(cid)
|
||||
self.assertEqual(channel.get_messages(), [])
|
||||
|
||||
c1.send(u"watch", channelid=cid)
|
||||
yield c1.sync()
|
||||
self.assertEqual(len(channel._listeners), 1)
|
||||
c1.strip_acks()
|
||||
self.assertEqual(c1.events, [])
|
||||
|
||||
c1.send(u"add", channelid=cid, phase="1", body="msg1A")
|
||||
yield c1.sync()
|
||||
c1.strip_acks()
|
||||
self.assertEqual(strip_messages(channel.get_messages()),
|
||||
[{"phase": "1", "body": "msg1A"}])
|
||||
self.assertEqual(len(c1.events), 1) # echo should be sent right away
|
||||
msg = yield c1.next_non_ack()
|
||||
self.assertEqual(msg["type"], "message")
|
||||
self.assertEqual(strip_message(msg["message"]),
|
||||
{"phase": "1", "body": "msg1A"})
|
||||
self.assertIn("server_tx", msg)
|
||||
self.assertIsInstance(msg["server_tx"], float)
|
||||
|
||||
c1.send(u"add", channelid=cid, phase="1", body="msg1B")
|
||||
c1.send(u"add", channelid=cid, phase="2", body="msg2A")
|
||||
|
||||
msg = yield c1.next_non_ack()
|
||||
self.assertEqual(msg["type"], "message")
|
||||
self.assertEqual(strip_message(msg["message"]),
|
||||
{"phase": "1", "body": "msg1B"})
|
||||
|
||||
msg = yield c1.next_non_ack()
|
||||
self.assertEqual(msg["type"], "message")
|
||||
self.assertEqual(strip_message(msg["message"]),
|
||||
{"phase": "2", "body": "msg2A"})
|
||||
|
||||
self.assertEqual(strip_messages(channel.get_messages()), [
|
||||
{"phase": "1", "body": "msg1A"},
|
||||
{"phase": "1", "body": "msg1B"},
|
||||
{"phase": "2", "body": "msg2A"},
|
||||
])
|
||||
|
||||
# second client should see everything
|
||||
c2 = yield self.make_client()
|
||||
msg = yield c2.next_non_ack()
|
||||
self.check_welcome(msg)
|
||||
c2.send(u"bind", appid=u"appid", side=u"side")
|
||||
c2.send(u"claim", channelid=cid)
|
||||
# 'watch' triggers delivery of old messages, in temporal order
|
||||
c2.send(u"watch", channelid=cid)
|
||||
|
||||
msg = yield c2.next_non_ack()
|
||||
self.assertEqual(msg["type"], "message")
|
||||
self.assertEqual(strip_message(msg["message"]),
|
||||
{"phase": "1", "body": "msg1A"})
|
||||
|
||||
msg = yield c2.next_non_ack()
|
||||
self.assertEqual(msg["type"], "message")
|
||||
self.assertEqual(strip_message(msg["message"]),
|
||||
{"phase": "1", "body": "msg1B"})
|
||||
|
||||
msg = yield c2.next_non_ack()
|
||||
self.assertEqual(msg["type"], "message")
|
||||
self.assertEqual(strip_message(msg["message"]),
|
||||
{"phase": "2", "body": "msg2A"})
|
||||
|
||||
# adding a duplicate is not an error, and clients will ignore it
|
||||
c1.send(u"add", channelid=cid, phase="2", body="msg2A")
|
||||
|
||||
# the duplicate message *does* get stored, and delivered
|
||||
msg = yield c2.next_non_ack()
|
||||
self.assertEqual(msg["type"], "message")
|
||||
self.assertEqual(strip_message(msg["message"]),
|
||||
{"phase": "2", "body": "msg2A"})
|
||||
|
||||
|
||||
class Summary(unittest.TestCase):
|
||||
def test_mailbox(self):
|
||||
c = rendezvous.Mailbox(None, None, None, False, None, None)
|
||||
|
|
Loading…
Reference in New Issue
Block a user