예제 #1
0
파일: test_listen.py 프로젝트: Linaro/squad
    def test_start(self, Popen):
        backend = Backend.objects.create(name="foo")
        manager = ListenerManager()

        manager.start(backend)

        self.assertEqual(Popen.call_args[0][-1][-1], "foo")
예제 #2
0
    def test_start(self, Popen):
        backend = Backend.objects.create(name="foo")
        manager = ListenerManager()

        manager.start(backend)

        self.assertEqual(Popen.call_args[0][-1][-1], "foo")
    def test_start(self, Popen):
        backend = Backend.objects.create(name="foo")
        manager = ListenerManager(argv)

        manager.start(backend)

        Popen.assert_called_with(argv + ['foo'])
예제 #4
0
    def test_start(self, Listener):
        backend = Backend.objects.create(name="foo")
        manager = ListenerManager()

        manager.start(backend)

        Listener.assert_called_with(backend)
        instance = Listener.return_value
        instance.start.assert_called_once()
예제 #5
0
    def test_handle_listener(self, Listener, ListenerManager, Backend):
        backend = object()
        Backend.objects.get.return_value = backend

        command = Command()
        command.handle(BACKEND='foo')

        ListenerManager.assert_not_called()
        Listener.assert_called_with(backend)
        Listener.return_value.run.assert_called()
예제 #6
0
파일: test_listen.py 프로젝트: Linaro/squad
    def test_handle_listener(self, Listener, ListenerManager, Backend):
        backend = object()
        Backend.objects.get.return_value = backend

        command = Command()
        command.handle(BACKEND='foo')

        ListenerManager.assert_not_called()
        Listener.assert_called_with(backend)
        Listener.return_value.run.assert_called()
예제 #7
0
파일: test_listen.py 프로젝트: Linaro/squad
    def test_stop(self, Popen):
        backend = Backend.objects.create(name="foo")
        manager = ListenerManager()

        Popen.return_value.poll.return_value = None

        manager.start(backend)
        manager.stop(backend.id)

        Popen.return_value.poll.assert_called_once()
        Popen.return_value.terminate.assert_called_once()
        Popen.return_value.wait.assert_called_once()
예제 #8
0
    def test_stop(self, Listener):
        backend = Backend.objects.create(name="foo")
        manager = ListenerManager()

        manager.start(backend)
        manager.stop(backend.id)

        Listener.return_value.terminate.assert_called_once()
예제 #9
0
    def test_cleanup(self, Listener):
        backend1 = Backend.objects.create(name="foo")
        backend2 = Backend.objects.create(name="bar")
        manager = ListenerManager()
        manager.start(backend1)
        manager.start(backend2)

        manager.stop = MagicMock()

        manager.cleanup()

        manager.stop.assert_has_calls([call(backend1.id), call(backend2.id)], any_order=True)
예제 #10
0
    def test_keep_listeners_running_changed(self, Listener):
        manager = ListenerManager()
        backend = Backend.objects.create(name="foo")

        # start existing backends
        manager.keep_listeners_running()

        manager.stop = MagicMock()
        manager.start = MagicMock()

        # backend is changed
        backend.name = 'bar'
        backend.save()
        manager.keep_listeners_running()

        manager.stop.assert_called_with(backend.id)
        manager.start.assert_called_with(backend)
예제 #11
0
    def test_keep_listeners_running_added(self, Listener):
        manager = ListenerManager()
        backend1 = Backend.objects.create(name="foo")

        manager.start = MagicMock()
        manager.stop = MagicMock()

        # start existing backends
        manager.keep_listeners_running()
        manager.start.assert_called_with(backend1)

        # new backend, start it too
        backend2 = Backend.objects.create(name="bar")
        manager.keep_listeners_running()
        manager.start.assert_called_with(backend2)

        manager.stop.assert_not_called()
예제 #12
0
    def test_keep_listeners_running_removed(self, Listener):
        manager = ListenerManager()
        backend = Backend.objects.create(name="foo")

        manager.stop = MagicMock()

        # start existing backends
        manager.keep_listeners_running()

        # backend is removed
        bid = backend.id
        backend.delete()
        manager.keep_listeners_running()
        manager.stop.assert_called_with(bid)
예제 #13
0
파일: test_listen.py 프로젝트: Linaro/squad
    def test_cleanup(self, Popen):
        backend1 = Backend.objects.create(name="foo")
        backend2 = Backend.objects.create(name="bar")
        manager = ListenerManager()
        manager.start(backend1)
        manager.start(backend2)

        manager.stop = MagicMock()

        manager.cleanup()

        manager.stop.assert_has_calls([call(backend1.id), call(backend2.id)], any_order=True)
예제 #14
0
    def test_stop(self, Popen):
        backend = Backend.objects.create(name="foo")
        manager = ListenerManager()

        Popen.return_value.poll.return_value = None

        manager.start(backend)
        manager.stop(backend.id)

        Popen.return_value.poll.assert_called_once()
        Popen.return_value.terminate.assert_called_once()
        Popen.return_value.wait.assert_called_once()
예제 #15
0
    def test_keep_listeners_running_restart_dead_process(self, Popen):
        manager = ListenerManager()
        backend = Backend.objects.create(name="foo")

        # start existing backends
        manager.keep_listeners_running()

        self.assertEqual(1, len(manager.__processes__))
        Popen.assert_called()

        # "kill" the process
        Popen.return_value.poll.return_value = -15  # SIGKILL
        manager.stop = MagicMock()
        manager.start = MagicMock()

        # Give it another go
        manager.keep_listeners_running()

        manager.stop.assert_called_with(backend.id)
        manager.start.assert_called_with(backend)
예제 #16
0
파일: test_listen.py 프로젝트: Linaro/squad
    def test_keep_listeners_running_changed(self, Popen):
        manager = ListenerManager()
        backend = Backend.objects.create(name="foo")

        # start existing backends
        manager.keep_listeners_running()

        manager.stop = MagicMock()
        manager.start = MagicMock()

        # backend is changed
        backend.name = 'bar'
        backend.save()
        manager.keep_listeners_running()

        manager.stop.assert_called_with(backend.id)
        manager.start.assert_called_with(backend)
예제 #17
0
파일: test_listen.py 프로젝트: Linaro/squad
    def test_keep_listeners_running_added(self, Popen):
        manager = ListenerManager()
        backend1 = Backend.objects.create(name="foo")

        manager.start = MagicMock()
        manager.stop = MagicMock()

        # start existing backends
        manager.keep_listeners_running()
        manager.start.assert_called_with(backend1)

        # new backend, start it too
        backend2 = Backend.objects.create(name="bar")
        manager.keep_listeners_running()
        manager.start.assert_called_with(backend2)

        manager.stop.assert_not_called()
예제 #18
0
파일: test_listen.py 프로젝트: Linaro/squad
    def test_keep_listeners_running_removed(self, Popen):
        manager = ListenerManager()
        backend = Backend.objects.create(name="foo")

        manager.stop = MagicMock()

        # start existing backends
        manager.keep_listeners_running()

        # backend is removed
        bid = backend.id
        backend.delete()
        manager.keep_listeners_running()
        manager.stop.assert_called_with(bid)
예제 #19
0
    def test_handle(self, ListenerManager):
        command = Command()
        command.handle()

        ListenerManager.assert_called_once()
        ListenerManager.return_value.run.assert_called_once()
예제 #20
0
파일: test_listen.py 프로젝트: Linaro/squad
    def test_handle(self, ListenerManager):
        command = Command()
        command.handle()

        ListenerManager.assert_called_once()
        ListenerManager.return_value.run.assert_called_once()