def test_StopListeningOnAnIDWhichIsNotListenedTo(self): tested = server.Server(self.checkInCallback, self.doneCallback, self.progressCallback) try: self.invokeStopListeningAndWaitTillDone(tested, "yuvu") self.validateCheckInDoesNotWork(tested, "yuvu") finally: tested.close()
def test_CheckIn(self): tested = server.Server(self.checkInCallback, self.doneCallback, self.progressCallback) try: tested.listenOnID("eliran") self.validateCheckIn(tested, "eliran") self.assertEquals(self.doneCallbackArguments, []) self.assertEquals(self.progressCallbackArguments, []) finally: tested.close()
def test_SendCommand(self): tested = server.Server(self.checkInCallback, self.doneCallback, self.progressCallback) try: tested.listenOnID("eliran") talk = talktoserver.TalkToServer(config.AMQP_URL, "eliran") tested.provideLabel("eliran", "fake label") self.assertEqualsWithinTimeout(talk.label, "fake label") finally: talk.close() tested.close()
def test_ProvideLabel(self): tested = server.Server(self.checkInCallback, self.doneCallback, self.progressCallback) try: tested.listenOnID("yuvu") self.validateCheckIn(tested, "yuvu") talk = talktoserver.TalkToServer(config.AMQP_URL, "yuvu") tested.provideLabel("yuvu", "thecoolestlabel") self.assertEqualsWithinTimeout(talk.label, "thecoolestlabel") finally: talk.close() tested.close()
def test_ListenTwiceOnSameID(self): tested = server.Server(self.checkInCallback, self.doneCallback, self.progressCallback) try: tested.listenOnID("yuvu") self.validateCheckIn(tested, "yuvu") tested.listenOnID("yuvu") self.validateCheckIn(tested, "yuvu") self.invokeStopListeningAndWaitTillDone(tested, "yuvu") self.validateCheckInDoesNotWork(tested, "yuvu") finally: tested.close()
def test_StopListening(self): tested = server.Server(self.checkInCallback, self.doneCallback, self.progressCallback) try: tested.listenOnID("yuvu") self.validateCheckIn(tested, "yuvu") self.invokeStopListeningAndWaitTillDone(tested, "yuvu") self.validateCheckInDoesNotWork(tested, "yuvu") tested.listenOnID("yuvu") self.validateCheckIn(tested, "yuvu") self.assertEquals(self.doneCallbackArguments, []) self.assertEquals(self.progressCallbackArguments, []) finally: tested.close()
def test_KillSelfInCasePikaConnectionCreationFailed(self): originalSelectConnection = server.pika.SelectConnection server.pika.SelectConnection = mock.Mock( side_effect=Exception("Catch me")) server.threading.Thread.__init__ = mock.Mock() server.threading.Thread.start = mock.Mock() server.threading.Thread.daemon = mock.Mock() server.threading.Event = mock.Mock() self.tested = server.Server(self.checkInCallback, self.doneInCallback, self.progressInCallback, self.failedCallback) with self.assertRaises(Exception): self.tested.run() self.fakeKill.assert_called_once_with(os.getpid(), signal.SIGTERM)
def setUp(self): self._logger = logging.getLogger() output = subprocess.check_output(["ps", "-Af"]) if 'beam.smp' in output: raise Exception( "It seems a previous instance of rabbitMQ is already running. " "Kill it to run this test") self.tempdir = tempfile.mkdtemp() self.rabbitMQWrapper = rabbitmqwrapper.RabbitMQWrapper(self.tempdir) self.checkInCallbackArguments = [] self.doneCallbackArguments = [] self.progressCallbackArguments = [] self.failedCallbackArguments = [] self.progressWaitEvents = dict() self.unreportedProgressMessageEvent = None self.auxLabelIDCounter = 0 self.doServerCallbackCauseErrors = False self.tested = server.Server(self.checkInCallback, self.doneCallback, self.progressCallback, self.failedCallback) self.talkToServerInstances = set()
def test_ExceptionInCallbackDoesNotCrashServer(self): badCheckInCallback = mock.Mock(side_effect=Exception("Exception during checkin, ignore me")) badProgressCallback = mock.Mock(side_effect=Exception("Exception during progress, ignore me")) badDoneCallback = mock.Mock(side_effect=Exception("Exception during done, ignore me")) tested = server.Server(badCheckInCallback, badDoneCallback, badProgressCallback) try: tested.listenOnID("yuvu") self.validateCheckInDoesNotWork(tested, "yuvu") self.assertGreater(badCheckInCallback.call_count, 0) checkInAttemptsArgs = set([arg[0] for arg in badCheckInCallback.call_args_list]) self.assertEquals(checkInAttemptsArgs, set([("yuvu",)])) self.validateStatusMessageArrival(tested, "progress", "yuvu", isArrivalExpected=False, extraArgs=("fake progress message",)) progressAttemptArgs = set([arg[0] for arg in badProgressCallback.call_args_list]) self.assertEquals(set([("yuvu", "fake progress message")]), progressAttemptArgs) self.validateStatusMessageArrival(tested, "done", "yuvu", isArrivalExpected=False) doneAttemptArgs = set([arg[0] for arg in badDoneCallback.call_args_list]) self.assertEquals(set([("yuvu",)]), doneAttemptArgs) self.assertTrue(tested.isAlive()) finally: tested.close()
def __init__(self, bindHostname): self._registered = {} self._server = server.Server(bindHostname=bindHostname, checkInCallback=self._checkIn, doneCallback=self._done)