def test_subscribe_error_after_a_cycle(self): with make_client(endpoint=endpoint, appkey=appkey, reconnect_interval=1) as client: old_received_message =\ client._internal.connection.on_incoming_text_frame client._internal.connection.on_incoming_text_frame =\ lambda *args: None so = SubscriptionObserver() so2 = SubscriptionObserver() client.subscribe(channel, SubscriptionMode.ADVANCED, so) client.unsubscribe(channel) client.subscribe(channel, SubscriptionMode.ADVANCED, so2) client._queue.join() self.assertEqual(client._internal.subscriptions[channel]._mode, 'cycle') old_received_message( '{"action":"rtm/subscribe/ok","body":{"channel":"' + channel + '","position":"position"},"id":0}') so.wait_subscribed() self.assertEqual(client._internal.subscriptions[channel]._mode, 'cycle') old_received_message( '{"action":"rtm/unsubscribe/ok","body":{},"id":1}') so.wait_not_subscribed() self.assertEqual(client._internal.subscriptions[channel]._mode, 'linked') old_received_message( '{"action":"rtm/subscribe/error","body":{},"id":2}') self.assertEqual(client._internal.subscriptions[channel]._mode, 'linked') self.assertEqual( client._internal.subscriptions[channel]._sm.get_state_name(), 'Subscription.Failed') so2.wait_failed() expected_log = [ 'on_leave_unsubscribed', 'on_enter_subscribing', 'on_leave_subscribing', 'on_enter_unsubscribing', 'on_leave_unsubscribing', 'on_enter_unsubscribed', 'on_deleted' ] expected_log2 = [ 'on_created', 'on_leave_unsubscribed', 'on_enter_subscribing', 'on_leave_subscribing', ('on_enter_failed', 'Subscribe error') ] self.assertEqual(so.log, expected_log) self.assertEqual(so2.log, expected_log2)
def test_subscribe_error(self): with make_client(endpoint=endpoint, appkey=appkey, reconnect_interval=1) as client: client.observer = ClientObserver() so = SubscriptionObserver() client.subscribe(channel, SubscriptionMode.ADVANCED, so, {'position': 'this_is_invalid_position'}) so.wait_failed() expected_log = [ 'on_leave_unsubscribed', 'on_enter_subscribing', 'on_leave_subscribing', ('on_enter_failed', 'Subscribe error') ] self.assertEqual(so.log, expected_log)