def test_no_connection(self): x = X(self.app) x.connection = None x.hub.timer.call_repeatedly = Mock( name='x.hub.timer.call_repeatedly()') x.blueprint.state = CLOSE synloop(*x.args) x.hub.timer.call_repeatedly.assert_not_called()
def test_updates_qos_when_changed(self): x = X(self.app) x.qos.prev = 2 x.qos.value = 2 x.timeout_then_error(x.connection.drain_events) with pytest.raises(socket.error): synloop(*x.args) x.qos.update.assert_not_called() x.qos.value = 4 x.timeout_then_error(x.connection.drain_events) with pytest.raises(socket.error): synloop(*x.args) x.qos.update.assert_called_with()
def test_updates_qos_when_changed(self): x = X(self.app) x.qos.prev = 2 x.qos.value = 2 x.timeout_then_error(x.connection.drain_events) with self.assertRaises(socket.error): synloop(*x.args) self.assertFalse(x.qos.update.called) x.qos.value = 4 x.timeout_then_error(x.connection.drain_events) with self.assertRaises(socket.error): synloop(*x.args) x.qos.update.assert_called_with()
def test_no_heartbeat_support(self): x = X(self.app) x.connection.supports_heartbeats = False x.obj.pool.is_green = True x.obj.timer.call_repeatedly = Mock( name='x.obj.timer.call_repeatedly()' ) def drain_events(timeout): x.blueprint.state = CLOSE x.connection.drain_events.side_effect = drain_events synloop(*x.args) x.obj.timer.call_repeatedly.assert_not_called()
def test_heartbeat_error(self): x = X(self.app, heartbeat=10) x.obj.pool.is_green = True def heartbeat_check(rate): raise RuntimeError('Heartbeat error') def call_repeatedly(rate, fn, args): fn(*args) x.connection.heartbeat_check = Mock(name='heartbeat_check', side_effect=heartbeat_check) x.obj.timer.call_repeatedly = call_repeatedly with pytest.raises(RuntimeError): synloop(*x.args)
def test_ignores_socket_errors_when_closed(self): x = X(self.app) x.close_then_error(x.connection.drain_events) assert synloop(*x.args) is None
def test_timeout_ignored(self): x = X(self.app) x.timeout_then_error(x.connection.drain_events) with pytest.raises(socket.error): synloop(*x.args) assert x.connection.drain_events.call_count == 2
def test_timeout_ignored(self): x = X(self.app) x.timeout_then_error(x.connection.drain_events) with self.assertRaises(socket.error): synloop(*x.args) self.assertEqual(x.connection.drain_events.call_count, 2)
def test_ignores_socket_errors_when_closed(self): x = X(self.app) x.close_then_error(x.connection.drain_events) self.assertIsNone(synloop(*x.args))