def test_send_remote_failover(self, should_try, send): should_try.return_value = True client = Client(servers=["http://example.com"], public_key="public", secret_key="secret", project=1) # test error send.side_effect = Exception() client.send_remote("http://example.com/api/store", "foo") self.assertEquals(client.state.status, client.state.ERROR) # test recovery send.side_effect = None client.send_remote("http://example.com/api/store", "foo") self.assertEquals(client.state.status, client.state.ONLINE)
def test_send_remote_failover(self, should_try, send): should_try.return_value = True client = Client(dsn="sync+http://public:[email protected]/1") # test error send.side_effect = Exception() client.send_remote("sync+http://example.com/api/store", client.encode({})) self.assertEquals(client.state.status, client.state.ERROR) # test recovery send.side_effect = None client.send_remote("sync+http://example.com/api/store", client.encode({})) self.assertEquals(client.state.status, client.state.ONLINE)
def test_send_remote_failover(self, should_try, send): should_try.return_value = True client = Client(dsn='sync+http://public:[email protected]/1') # test error send.side_effect = Exception() client.send_remote('sync+http://example.com/api/store', 'foo') self.assertEquals(client.state.status, client.state.ERROR) # test recovery send.side_effect = None client.send_remote('sync+http://example.com/api/store', 'foo') self.assertEquals(client.state.status, client.state.ONLINE)
def test_send_remote_failover_with_retry_after(self, should_try, send): should_try.return_value = True client = Client(dsn="sync+http://public:[email protected]/1") # test error send.side_effect = RateLimited("foo", 5) client.send_remote("sync+http://example.com/api/1/store/", client.encode({})) self.assertEquals(client.state.status, client.state.ERROR) self.assertEqual(client.state.retry_after, 5) # test recovery send.side_effect = None client.send_remote("sync+http://example.com/api/1/store/", client.encode({})) self.assertEquals(client.state.status, client.state.ONLINE) self.assertEqual(client.state.retry_after, 0)
def test_send_remote_failover_with_retry_after(self, should_try, send): should_try.return_value = True client = Client(dsn='sync+http://public:[email protected]/1') # test error send.side_effect = RateLimited('foo', 5) client.send_remote('sync+http://example.com/api/1/store/', client.encode({})) self.assertEquals(client.state.status, client.state.ERROR) self.assertEqual(client.state.retry_after, 5) # test recovery send.side_effect = None client.send_remote('sync+http://example.com/api/1/store/', client.encode({})) self.assertEquals(client.state.status, client.state.ONLINE) self.assertEqual(client.state.retry_after, 0)
def test_send_remote_failover(self, should_try, send_remote): should_try.return_value = True client = Client( servers=['http://example.com'], public_key='public', secret_key='secret', project=1, ) # test error send_remote.side_effect = Exception() client.send_remote('http://example.com/api/store', 'foo') self.assertEquals(client.state.status, client.state.ERROR) # test recovery send_remote.side_effect = None client.send_remote('http://example.com/api/store', 'foo') self.assertEquals(client.state.status, client.state.ONLINE)
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)
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_send_remote_failover_with_retry_after(self, should_try, send): should_try.return_value = True client = Client( dsn='sync+http://public:[email protected]/1' ) e = HTTPError( 'http://example.com/api/store', 429, 'oops', {'Retry-After': '5'}, StringIO()) # test error send.side_effect = e client.send_remote('sync+http://example.com/api/store', 'foo') self.assertEquals(client.state.status, client.state.ERROR) self.assertEqual(client.state.retry_after, 5) # test recovery send.side_effect = None client.send_remote('sync+http://example.com/api/store', 'foo') self.assertEquals(client.state.status, client.state.ONLINE) self.assertEqual(client.state.retry_after, 0)