def test_async_send_remote_failover(self, should_try, get_transport): should_try.return_value = True async_transport = AsyncTransport() async_transport.async_send = async_send = mock.Mock() get_transport.return_value = async_transport client = Client(dsn='http://*****:*****@example.com/1', ) # test immediate raise of error async_send.side_effect = Exception() client.send_remote('http://example.com/api/1/store/', client.encode({})) self.assertEquals(client.state.status, client.state.ERROR) # test recovery client.send_remote('http://example.com/api/1/store/', client.encode({})) success_cb = async_send.call_args[0][3] success_cb() self.assertEquals(client.state.status, client.state.ONLINE) # test delayed raise of error client.send_remote('http://example.com/api/1/store/', client.encode({})) failure_cb = async_send.call_args[0][4] failure_cb(Exception()) self.assertEquals(client.state.status, client.state.ERROR)
def test_async_send_remote_failover(self, should_try, get_transport): should_try.return_value = True async_transport = AsyncTransport() async_transport.async_send = async_send = mock.Mock() get_transport.return_value = async_transport client = Client( servers=['http://example.com'], public_key='public', secret_key='secret', project=1, ) # test immediate raise of error async_send.side_effect = Exception() client.send_remote('http://example.com/api/store', 'foo') self.assertEquals(client.state.status, client.state.ERROR) # test recovery client.send_remote('http://example.com/api/store', 'foo') success_cb = async_send.call_args[0][2] success_cb() self.assertEquals(client.state.status, client.state.ONLINE) # test delayed raise of error client.send_remote('http://example.com/api/store', 'foo') failure_cb = async_send.call_args[0][3] failure_cb(Exception()) self.assertEquals(client.state.status, client.state.ERROR)