def test_tryConnection_will_retry_in_3_seconds_if_autoReconnect_set(self): listener = PostgresListenerService() listener.autoReconnect = True startConnection = self.patch(listener, "startConnection") startConnection.side_effect = factory.make_exception() deferLater = self.patch(listener_module, "deferLater") deferLater.return_value = sentinel.retry result = yield listener.tryConnection() self.assertThat(result, Is(sentinel.retry)) self.assertThat(deferLater, MockCalledWith(reactor, 3, ANY))
def test_tryConnection_will_not_retry_if_autoReconnect_not_set(self): listener = PostgresListenerService() listener.autoReconnect = False exception_type = factory.make_exception_type() exception_message = factory.make_name("message") startConnection = self.patch(listener, "startConnection") startConnection.side_effect = exception_type(exception_message) deferLater = self.patch(listener_module, "deferLater") deferLater.return_value = sentinel.retry with ExpectedException(exception_type): yield listener.tryConnection() self.assertThat(deferLater, MockNotCalled())