def test_ack(self): """ Test ack """ # no hello ret = self.msg(self.ws, {"messageType": "ack", "updates": [{"channelID": "ack_chan_1", "version": 23}]}) self.compare_dict(ret, {"error": "Invalid Command", "status": 401, "messageType": "ack"}) self.assertEqual(ret["updates"][0]["channelID"], "ack_chan_1") self.assertEqual(ret["updates"][0]["version"], 23) # happy path self.msg(self.ws, {"messageType": "hello", "channelIDs": ["ack_chan_1"], "uaid": get_uaid("ack_uaid")}) reg = self.msg(self.ws, {"messageType": "register", "channelID": "ack_chan_1"}) assert (reg["pushEndpoint"] is not None) # send an http PUT request to the endpoint send_http_put(reg['pushEndpoint']) # this blocks the socket on read # print 'RECV', self.ws.recv() # hanging socket against AWS ret = self.msg(self.ws, {"messageType": "ack", "updates": [{"channelID": "ack_chan_1", "version": 23}]}) self.compare_dict(ret, {"messageType": "notification"}) self.assertEqual(ret["updates"][0]["channelID"], "ack_chan_1")
def test_unreg_race(self): """ Test Unregister with outstanding unACKed notifications https://bugzilla.mozilla.org/show_bug.cgi?id=894193 """ class TimeoutError(Exception): pass def _timeout(signum, frame): raise TimeoutError() self.msg(self.ws, {"messageType": "hello", "channelIDs": [], "uaid": "unreg_race"}) ret = self.msg(self.ws, {"messageType": "register", "channelID": "unreg_race"}) send_http_put(ret["pushEndpoint"]) try: # read the update, but don't ACK it. self.ws.recv() # unregister the channel self.msg(self.ws, {"messageType": "unregister", "channelID": "unreg_race"}) # make sure we don't get any updates. # They should be immediate. signal.signal(signal.SIGALRM, _timeout) signal.alarm(1) self.ws.recv() raise AssertionError("ACK of unregistered channel data requested") except TimeoutError, e: pass
def test_ack(self): """ Test ack """ # no hello ret = self.msg( self.ws, { "messageType": "ack", "updates": [{ "channelID": "ack_chan_1", "version": 23 }] }) self.compare_dict(ret, { "error": "Invalid Command", "status": 401, "messageType": "ack" }) self.assertEqual(ret["updates"][0]["channelID"], "ack_chan_1") self.assertEqual(ret["updates"][0]["version"], 23) # happy path self.msg( self.ws, { "messageType": "hello", "channelIDs": ["ack_chan_1"], "uaid": get_uaid("ack_uaid") }) reg = self.msg(self.ws, { "messageType": "register", "channelID": "ack_chan_1" }) assert (reg["pushEndpoint"] is not None) # send an http PUT request to the endpoint send_http_put(reg['pushEndpoint']) # this blocks the socket on read # print 'RECV', self.ws.recv() # hanging socket against AWS ret = self.msg( self.ws, { "messageType": "ack", "updates": [{ "channelID": "ack_chan_1", "version": 23 }] }) self.compare_dict(ret, {"messageType": "notification"}) self.assertEqual(ret["updates"][0]["channelID"], "ack_chan_1")
def send_update(update_url, str_data, state='update1', ct='application/x-www-form-urlencoded'): if update_url == '': raise AssertionError("No update_url found") ws.state = state resp = send_http_put(update_url, str_data, ct, True) _assert_equal(resp, 200)
def test_unreg_race(self): """ Test Unregister with outstanding unACKed notifications https://bugzilla.mozilla.org/show_bug.cgi?id=894193 """ class TimeoutError(Exception): pass def _timeout(signum, frame): raise TimeoutError() self.msg(self.ws, { "messageType": "hello", "channelIDs": [], "uaid": "unreg_race" }) ret = self.msg(self.ws, { "messageType": "register", "channelID": "unreg_race" }) send_http_put(ret["pushEndpoint"]) try: # read the update, but don't ACK it. self.ws.recv() # unregister the channel self.msg(self.ws, { "messageType": "unregister", "channelID": "unreg_race" }) # make sure we don't get any updates. # They should be immediate. signal.signal(signal.SIGALRM, _timeout) signal.alarm(1) self.ws.recv() raise AssertionError("ACK of unregistered channel data requested") except TimeoutError, e: pass