Example #1
0
    def test_signal(self):
        yield self.start_arbiter(check_delay=1.0)
        resp = yield self.numprocesses('incr', name='test')
        self.assertEqual(resp, 2)
        # wait for both to have started
        resp = yield async_poll_for(self.test_file, 'STARTSTART')
        self.assertTrue(resp)
        truncate_file(self.test_file)

        pids = yield self.pids()
        self.assertEqual(len(pids), 2)
        to_kill = pids[0]
        status = yield self.status('signal', name='test', pid=to_kill,
                                   signum=SIGKILL)
        self.assertEqual(status, 'ok')

        # make sure the process is restarted
        res = yield async_poll_for(self.test_file, 'START')
        self.assertTrue(res)

        # we still should have two processes, but not the same pids for them
        pids = yield self.pids()
        count = 0
        while len(pids) < 2 and count < 10:
            pids = yield self.pids()
            time.sleep(.1)
        self.assertEqual(len(pids), 2)
        self.assertTrue(to_kill not in pids)
        yield self.stop_arbiter()
Example #2
0
    def test_max_age(self):
        # let's run 15 processes
        self.numprocesses('incr', name='test', nb=14)
        initial_pids = self.pids()

        # we want to make sure the watcher is really up and running 14
        # processes, and stable
        poll_for(self.test_file, 'START' * 15)
        truncate_file(self.test_file)  # make sure we have a clean slate

        # we want a max age of 1 sec.
        result = self.call('set', name='test',
                           options={'max_age': 1, 'max_age_variance': 0})

        self.assertEquals(result.get('status'), 'ok')

        # we want to wait for all 15 processes to restart
        ready = False

        def _ready(olds, news):
            for pid in olds:
                if pid in news:
                    return False
            return True

        started = time.time()
        while not ready:
            if time.time() - started > 10.:
                break
            time.sleep(.1)
            ready = _ready(initial_pids, self.pids())

        current_pids = self.pids()
        self.assertEqual(len(current_pids), 15)
        self.assertNotEqual(initial_pids, current_pids)
Example #3
0
    def test_reload_wid_1_worker(self):
        yield self.start_arbiter(graceful_timeout=0)

        resp = yield self._call("stats", name="test")
        processes1 = list(resp['info'].keys())
        self.assertEqual(len(processes1), 1)
        wids1 = [resp['info'][process]['wid'] for process in processes1]
        self.assertEqual(wids1, [1])

        truncate_file(self.test_file)  # clean slate
        yield self._call("reload")
        res = yield async_poll_for(self.test_file, 'START')  # restarted
        self.assertTrue(res)

        resp = yield self._call("stats", name="test")
        processes2 = list(resp['info'].keys())
        self.assertEqual(len(processes2), 1)
        self.assertNotEqual(processes1, processes2)
        wids2 = [resp['info'][process]['wid'] for process in processes2]
        self.assertEqual(wids2, [2])

        truncate_file(self.test_file)  # clean slate
        yield self._call("reload")
        res = yield async_poll_for(self.test_file, 'START')  # restarted
        self.assertTrue(res)

        resp = yield self._call("stats", name="test")
        processes3 = list(resp['info'].keys())
        self.assertEqual(len(processes3), 1)
        self.assertNotIn(processes3[0], (processes1[0], processes2[0]))
        wids3 = [resp['info'][process]['wid'] for process in processes3]
        self.assertEqual(wids3, [1])

        yield self.stop_arbiter()
Example #4
0
    def test_reload_wid_4_workers(self):
        yield self.start_arbiter(graceful_timeout=0)
        resp = yield self._call("incr", name="test", nb=3)
        self.assertEqual(resp.get('numprocesses'), 4)

        resp = yield self._call("stats", name="test")
        processes1 = list(resp['info'].keys())
        self.assertEqual(len(processes1), 4)
        wids1 = set(resp['info'][process]['wid'] for process in processes1)
        self.assertSetEqual(wids1, set([1, 2, 3, 4]))

        truncate_file(self.test_file)  # clean slate
        yield self._call("reload")
        self.assertTrue(async_poll_for(self.test_file, 'START'))  # restarted

        resp = yield self._call("stats", name="test")
        processes2 = list(resp['info'].keys())
        self.assertEqual(len(processes2), 4)
        self.assertEqual(len(set(processes1) & set(processes2)), 0)
        wids2 = set(resp['info'][process]['wid'] for process in processes2)
        self.assertSetEqual(wids2, set([5, 6, 7, 8]))

        truncate_file(self.test_file)  # clean slate
        yield self._call("reload")
        self.assertTrue(async_poll_for(self.test_file, 'START'))  # restarted

        resp = yield self._call("stats", name="test")
        processes3 = list(resp['info'].keys())
        self.assertEqual(len(processes3), 4)
        self.assertEqual(len(set(processes1) & set(processes3)), 0)
        self.assertEqual(len(set(processes2) & set(processes3)), 0)
        wids3 = set([resp['info'][process]['wid'] for process in processes3])
        self.assertSetEqual(wids3, set([1, 2, 3, 4]))

        yield self.stop_arbiter()
Example #5
0
    def test_signal(self):
        self.assertEquals(self.numprocesses('incr', name='test'), 2)
        # wait for both to have started
        self.assertTrue(poll_for(self.test_file, 'STARTSTART'))
        truncate_file(self.test_file)

        pids = self.pids()
        self.assertEquals(len(pids), 2)
        to_kill = pids[0]
        self.assertEquals(
            self.status('signal',
                        name='test',
                        pid=to_kill,
                        signum=signal.SIGKILL), 'ok')

        # make sure the process is restarted
        self.assertTrue(poll_for(self.test_file, 'START'))

        # we still should have two processes, but not the same pids for them
        pids = self.pids()
        count = 0
        while len(pids) < 2 and count < 10:
            pids = self.pids()
            time.sleep(.1)
        self.assertEquals(len(pids), 2)
        self.assertTrue(to_kill not in pids)
Example #6
0
    def test_reload_wid_4_workers(self):
        yield self.start_arbiter(graceful_timeout=0)
        resp = yield self._call("incr", name="test", nb=3)
        self.assertEqual(resp.get('numprocesses'), 4)

        resp = yield self._call("stats", name="test")
        processes1 = list(resp['info'].keys())
        self.assertEqual(len(processes1), 4)
        wids1 = set(resp['info'][process]['wid'] for process in processes1)
        self.assertSetEqual(wids1, set([1, 2, 3, 4]))

        truncate_file(self.test_file)  # clean slate
        yield self._call("reload")
        self.assertTrue(async_poll_for(self.test_file, 'START'))  # restarted

        resp = yield self._call("stats", name="test")
        processes2 = list(resp['info'].keys())
        self.assertEqual(len(processes2), 4)
        self.assertEqual(len(set(processes1) & set(processes2)), 0)
        wids2 = set(resp['info'][process]['wid'] for process in processes2)
        self.assertSetEqual(wids2, set([5, 6, 7, 8]))

        truncate_file(self.test_file)  # clean slate
        yield self._call("reload")
        self.assertTrue(async_poll_for(self.test_file, 'START'))  # restarted

        resp = yield self._call("stats", name="test")
        processes3 = list(resp['info'].keys())
        self.assertEqual(len(processes3), 4)
        self.assertEqual(len(set(processes1) & set(processes3)), 0)
        self.assertEqual(len(set(processes2) & set(processes3)), 0)
        wids3 = set([resp['info'][process]['wid'] for process in processes3])
        self.assertSetEqual(wids3, set([1, 2, 3, 4]))

        yield self.stop_arbiter()
Example #7
0
    def test_stop_and_restart(self):
        # cf https://github.com/circus-tent/circus/issues/912

        yield self._start_arbiter()
        # wait for the process to be started
        res1 = yield async_poll_for(self.stdout, 'stdout')
        res2 = yield async_poll_for(self.stderr, 'stderr')
        self.assertTrue(res1)
        self.assertTrue(res2)
        self.assertFalse(self.stdout_stream._file.closed)
        self.assertFalse(self.stderr_stream._file.closed)

        # clean slate
        truncate_file(self.stdout)
        truncate_file(self.stderr)

        # stop the watcher
        yield self.arbiter.watchers[0].stop()

        self.assertTrue(self.stdout_stream._file.closed)
        self.assertTrue(self.stderr_stream._file.closed)

        # start it again
        yield self.arbiter.watchers[0].start()

        # wait for the process to be restarted
        res1 = yield async_poll_for(self.stdout, 'stdout')
        res2 = yield async_poll_for(self.stderr, 'stderr')
        self.assertTrue(res1)
        self.assertTrue(res2)
        self.assertFalse(self.stdout_stream._file.closed)
        self.assertFalse(self.stderr_stream._file.closed)

        yield self.stop_arbiter()
Example #8
0
    def test_plugins(self):
        # killing the setUp runner
        self._stop_runners()
        self.cli.stop()

        fd, datafile = mkstemp()
        os.close(fd)

        # setting up a circusd with a plugin
        dummy_process = 'circus.tests.support.run_process'
        plugin = 'circus.tests.test_arbiter.Plugin'
        plugins = [{'use': plugin, 'file': datafile}]
        self._run_circus(dummy_process, plugins=plugins)

        # doing a few operations
        def nb_processes():
            return len(cli.send_message('list', name='test').get('pids'))

        def incr_processes():
            return cli.send_message('incr', name='test')

        # wait for the plugin to be started
        self.assertTrue(poll_for(datafile, 'PLUGIN STARTED'))

        cli = CircusClient()
        self.assertEqual(nb_processes(), 1)
        incr_processes()
        self.assertEqual(nb_processes(), 2)
        # wait for the plugin to receive the signal
        self.assertTrue(poll_for(datafile, 'test:spawn'))
        truncate_file(datafile)
        incr_processes()
        self.assertEqual(nb_processes(), 3)
        # wait for the plugin to receive the signal
        self.assertTrue(poll_for(datafile, 'test:spawn'))
Example #9
0
    def test_plugins(self):
        # killing the setUp runner
        self._stop_runners()
        self.cli.stop()

        fd, datafile = mkstemp()
        os.close(fd)

        # setting up a circusd with a plugin
        dummy_process = 'circus.tests.support.run_process'
        plugin = 'circus.tests.test_arbiter.Plugin'
        plugins = [{'use': plugin, 'file': datafile}]
        self._run_circus(dummy_process, plugins=plugins)

        # doing a few operations
        def nb_processes():
            return len(cli.send_message('list', name='test').get('pids'))

        def incr_processes():
            return cli.send_message('incr', name='test')

        # wait for the plugin to be started
        self.assertTrue(poll_for(datafile, 'PLUGIN STARTED'))

        cli = CircusClient()
        self.assertEqual(nb_processes(), 1)
        incr_processes()
        self.assertEqual(nb_processes(), 2)
        # wait for the plugin to receive the signal
        self.assertTrue(poll_for(datafile, 'test:spawn'))
        truncate_file(datafile)
        incr_processes()
        self.assertEqual(nb_processes(), 3)
        # wait for the plugin to receive the signal
        self.assertTrue(poll_for(datafile, 'test:spawn'))
Example #10
0
    def test_max_age(self):
        # let's run 15 processes
        self.numprocesses('incr', name='test', nb=14)
        initial_pids = self.pids()

        # we want a max age of 2 sec.
        result = self.call('set',
                           name='test',
                           options={
                               'max_age': 1,
                               'max_age_variance': 0
                           })

        self.assertEquals(result.get('status'), 'ok')

        # let's wait 1.2 sec.
        time.sleep(1.2)

        truncate_file(self.test_file)  # make sure we have a clean slate
        # expect at least one restart (max_age and restart), in less than 5s
        self.assertTrue(
            poll_for(self.test_file, ('QUITSTOPSTART', 'QUITSTART')))
        current_pids = self.pids()

        self.assertEqual(len(current_pids), 15)
        self.assertNotEqual(initial_pids, current_pids)
Example #11
0
    def test_stop_and_restart(self):
        # cf https://github.com/circus-tent/circus/issues/912

        yield self._start_arbiter()
        # wait for the process to be started
        res1 = yield async_poll_for(self.stdout, 'stdout')
        res2 = yield async_poll_for(self.stderr, 'stderr')
        self.assertTrue(res1)
        self.assertTrue(res2)
        self.assertFalse(self.stdout_stream._file.closed)
        self.assertFalse(self.stderr_stream._file.closed)

        # clean slate
        truncate_file(self.stdout)
        truncate_file(self.stderr)

        # stop the watcher
        yield self.arbiter.watchers[0].stop()

        self.assertTrue(self.stdout_stream._file.closed)
        self.assertTrue(self.stderr_stream._file.closed)

        # start it again
        yield self.arbiter.watchers[0].start()

        # wait for the process to be restarted
        res1 = yield async_poll_for(self.stdout, 'stdout')
        res2 = yield async_poll_for(self.stderr, 'stderr')
        self.assertTrue(res1)
        self.assertTrue(res2)
        self.assertFalse(self.stdout_stream._file.closed)
        self.assertFalse(self.stderr_stream._file.closed)

        yield self.stop_arbiter()
Example #12
0
    def test_reload_wid_1_worker(self):
        yield self.start_arbiter(graceful_timeout=0)

        resp = yield self._call("stats", name="test")
        processes1 = list(resp['info'].keys())
        self.assertEqual(len(processes1), 1)
        wids1 = [resp['info'][process]['wid'] for process in processes1]
        self.assertEqual(wids1, [1])

        truncate_file(self.test_file)  # clean slate
        yield self._call("reload")
        res = yield async_poll_for(self.test_file, 'START')  # restarted
        self.assertTrue(res)

        resp = yield self._call("stats", name="test")
        processes2 = list(resp['info'].keys())
        self.assertEqual(len(processes2), 1)
        self.assertNotEqual(processes1, processes2)
        wids2 = [resp['info'][process]['wid'] for process in processes2]
        self.assertEqual(wids2, [2])

        truncate_file(self.test_file)  # clean slate
        yield self._call("reload")
        res = yield async_poll_for(self.test_file, 'START')  # restarted
        self.assertTrue(res)

        resp = yield self._call("stats", name="test")
        processes3 = list(resp['info'].keys())
        self.assertEqual(len(processes3), 1)
        self.assertNotIn(processes3[0], (processes1[0], processes2[0]))
        wids3 = [resp['info'][process]['wid'] for process in processes3]
        self.assertEqual(wids3, [1])

        yield self.stop_arbiter()
Example #13
0
    def test_max_age(self):
        result = self.call("set", name="test", options={"max_age": 1, "max_age_variance": 0})
        self.assertEquals(result.get("status"), "ok")
        initial_pids = self.pids()

        truncate_file(self.test_file)  # make sure we have a clean slate
        # expect at least one restart (max_age and restart), in less than 5s
        self.assertTrue(poll_for(self.test_file, ("QUITSTOPSTART", "QUITSTART")))
        current_pids = self.pids()
        self.assertEqual(len(current_pids), 1)
        self.assertNotEqual(initial_pids, current_pids)
Example #14
0
    def test_max_age(self):
        result = self.call('set', name='test',
                           options={'max_age': 1, 'max_age_variance': 0})
        self.assertEquals(result.get('status'), 'ok')
        initial_pids = self.pids()

        truncate_file(self.test_file)  # make sure we have a clean slate
        # expect at least one restart (max_age and restart), in less than 5s
        self.assertTrue(poll_for(self.test_file, 'QUITSTART'))
        current_pids = self.pids()
        self.assertEqual(len(current_pids), 1)
        self.assertNotEqual(initial_pids, current_pids)
Example #15
0
    def test_max_age(self):
        result = self.call('set', name='test',
                           options={'max_age': 1, 'max_age_variance': 0})
        self.assertEquals(result.get('status'), 'ok')
        initial_pids = self.pids()

        truncate_file(self.test_file)  # make sure we have a clean slate
        # expect at least one restart (max_age and restart), in less than 5s
        self.assertTrue(poll_for(self.test_file, 'QUITSTART'))
        current_pids = self.pids()
        self.assertEqual(len(current_pids), 1)
        self.assertNotEqual(initial_pids, current_pids)
Example #16
0
    def test_stream(self):
        # wait for the process to be started
        self.assertTrue(poll_for(self.stdout, 'stdout'))
        self.assertTrue(poll_for(self.stderr, 'stderr'))

        # restart and make sure streams are still working
        self.call('restart')
        truncate_file(self.stdout)
        truncate_file(self.stderr)

        # wait for the process to be restarted
        self.assertTrue(poll_for(self.stdout, 'stdout'))
        self.assertTrue(poll_for(self.stderr, 'stderr'))
Example #17
0
    def test_stream(self):
        # wait for the process to be started
        self.assertTrue(poll_for(self.stdout, "stdout"))
        self.assertTrue(poll_for(self.stderr, "stderr"))

        # clean slate
        truncate_file(self.stdout)
        truncate_file(self.stderr)
        # restart and make sure streams are still working
        self.call("restart")

        # wait for the process to be restarted
        self.assertTrue(poll_for(self.stdout, "stdout"))
        self.assertTrue(poll_for(self.stderr, "stderr"))
Example #18
0
    def test_reload1(self):
        msg1 = make_message("list", name="test")
        resp = self.cli.call(msg1)
        processes1 = resp.get('pids')

        truncate_file(self.test_file)  # clean slate
        self.cli.call(make_message("reload"))
        self.assertTrue(poll_for(self.test_file, 'START'))  # restarted

        msg2 = make_message("list", name="test")
        resp = self.cli.call(msg2)
        processes2 = resp.get('pids')

        self.assertNotEqual(processes1, processes2)
Example #19
0
    def test_stream(self):
        # wait for the process to be started
        self.assertTrue(poll_for(self.stdout, 'stdout'))
        self.assertTrue(poll_for(self.stderr, 'stderr'))

        # clean slate
        truncate_file(self.stdout)
        truncate_file(self.stderr)
        # restart and make sure streams are still working
        self.call('restart')

        # wait for the process to be restarted
        self.assertTrue(poll_for(self.stdout, 'stdout'))
        self.assertTrue(poll_for(self.stderr, 'stderr'))
Example #20
0
    def test_reload1(self):
        msg1 = make_message("list", name="test")
        resp = self.cli.call(msg1)
        processes1 = resp.get('pids')

        truncate_file(self.test_file)  # clean slate
        self.cli.call(make_message("reload"))
        self.assertTrue(poll_for(self.test_file, 'START'))  # restarted

        msg2 = make_message("list", name="test")
        resp = self.cli.call(msg2)
        processes2 = resp.get('pids')

        self.assertNotEqual(processes1, processes2)
Example #21
0
 def test_reload_sequential(self):
     yield self.start_arbiter(graceful_timeout=0)
     name = 'test_reload_sequential'
     options = self._get_options(numprocesses=4)
     yield self._call("add", name=name, cmd=self._get_cmd(),
                      start=True, options=options)
     resp = yield self._call("list", name=name)
     processes1 = resp.get('pids')
     truncate_file(self.test_file)  # clean slate
     yield self._call("reload", sequential=True)
     self.assertTrue(async_poll_for(self.test_file, 'START'))  # restarted
     resp = yield self._call("list", name=name)
     processes2 = resp.get('pids')
     self.assertNotEqual(processes1, processes2)
     yield self.stop_arbiter()
Example #22
0
    def test_reload2(self):
        yield self.start_arbiter(graceful_timeout=0)
        resp = yield self._call("list", name="test")
        processes1 = resp.get('pids')
        self.assertEqual(len(processes1), 1)

        truncate_file(self.test_file)  # clean slate
        yield self._call("reload")
        self.assertTrue(async_poll_for(self.test_file, 'START'))  # restarted

        resp = yield self._call("list", name="test")
        processes2 = resp.get('pids')
        self.assertEqual(len(processes2), 1)
        self.assertNotEqual(processes1[0], processes2[0])
        yield self.stop_arbiter()
Example #23
0
    def test_reload2(self):
        yield self.start_arbiter(graceful_timeout=0)
        resp = yield self._call("list", name="test")
        processes1 = resp.get('pids')
        self.assertEqual(len(processes1), 1)

        truncate_file(self.test_file)  # clean slate
        yield self._call("reload")
        self.assertTrue(async_poll_for(self.test_file, 'START'))  # restarted

        resp = yield self._call("list", name="test")
        processes2 = resp.get('pids')
        self.assertEqual(len(processes2), 1)
        self.assertNotEqual(processes1[0], processes2[0])
        yield self.stop_arbiter()
Example #24
0
    def test_stream(self):
        wait_for_value(self.data, 10)
        print(self.data)

        # wait for the process to be started
        self.assertTrue(poll_for(self.stdout, 'stdout'))
        self.assertTrue(poll_for(self.stderr, 'stderr'))

        # clean slate
        truncate_file(self.stdout)
        truncate_file(self.stderr)
        # restart and make sure streams are still working
        self.call('restart')

        # wait for the process to be restarted
        self.assertTrue(poll_for(self.stdout, 'stdout'))
        self.assertTrue(poll_for(self.stderr, 'stderr'))
Example #25
0
    def test_signal(self):
        self.assertEquals(self.numprocesses("incr", name="test"), 2)
        # wait for both to have started
        self.assertTrue(poll_for(self.test_file, "STARTSTART"))
        truncate_file(self.test_file)

        pids = self.pids()
        self.assertEquals(len(pids), 2)
        to_kill = pids[0]
        self.assertEquals(self.status("signal", name="test", pid=to_kill, signum=signal.SIGKILL), "ok")

        # make sure process is restarted
        self.assertTrue(poll_for(self.test_file, "START"))

        # we still should have two processes, but not the same pids for them
        pids = self.pids()
        self.assertEquals(len(pids), 2)
        self.assertTrue(to_kill not in pids)
Example #26
0
    def test_plugins(self):
        fd, datafile = mkstemp()
        os.close(fd)

        # setting up a circusd with a plugin
        plugin = 'circus.tests.test_arbiter.Plugin'
        plugins = [{'use': plugin, 'file': datafile}]

        yield self.start_arbiter(graceful_timeout=0,
                                 plugins=plugins,
                                 loop=get_ioloop())

        def incr_processes(cli):
            # return a coroutine if cli is Async
            return cli.send_message('incr', name='test')

        # wait for the plugin to be started
        res = yield async_poll_for(datafile, 'PLUGIN STARTED')
        self.assertTrue(res)

        cli = AsyncCircusClient(endpoint=self.arbiter.endpoint)

        res = yield cli.send_message('list', name='test')
        self.assertEqual(len(res.get('pids')), 1)

        yield incr_processes(cli)
        res = yield cli.send_message('list', name='test')
        self.assertEqual(len(res.get('pids')), 2)
        # wait for the plugin to receive the signal
        res = yield async_poll_for(datafile, 'test:spawn')
        self.assertTrue(res)
        truncate_file(datafile)

        yield incr_processes(cli)
        res = yield cli.send_message('list', name='test')
        self.assertEqual(len(res.get('pids')), 3)

        # wait for the plugin to receive the signal
        res = yield async_poll_for(datafile, 'test:spawn')
        self.assertTrue(res)
        os.remove(datafile)
        yield self.stop_arbiter()
Example #27
0
    def test_reload_uppercase(self):
        yield self.start_arbiter(graceful_timeout=0)
        name = 'test_RELOAD'
        yield self._call("add", name=name, cmd=self._get_cmd(),
                         start=True, options=self._get_options())

        resp = yield self._call("list", name=name)
        processes1 = resp.get('pids')

        truncate_file(self.test_file)  # clean slate

        yield self._call("reload")
        res = yield async_poll_for(self.test_file, 'START')
        self.assertTrue(res)  # restarted

        resp = yield self._call("list", name=name)
        processes2 = resp.get('pids')

        self.assertNotEqual(processes1, processes2)
        yield self.stop_arbiter()
Example #28
0
    def test_reload_uppercase(self):
        yield self.start_arbiter(graceful_timeout=0)
        name = 'test_RELOAD'
        yield self._call("add", name=name, cmd=self._get_cmd(),
                         start=True, options=self._get_options())

        resp = yield self._call("list", name=name)
        processes1 = resp.get('pids')

        truncate_file(self.test_file)  # clean slate

        yield self._call("reload")
        res = yield async_poll_for(self.test_file, 'START')
        self.assertTrue(res)  # restarted

        resp = yield self._call("list", name=name)
        processes2 = resp.get('pids')

        self.assertNotEqual(processes1, processes2)
        yield self.stop_arbiter()
Example #29
0
    def test_stream(self):
        yield self._start_arbiter()
        # wait for the process to be started
        res1 = yield async_poll_for(self.stdout, 'stdout')
        res2 = yield async_poll_for(self.stderr, 'stderr')
        self.assertTrue(res1)
        self.assertTrue(res2)

        # clean slate
        truncate_file(self.stdout)
        truncate_file(self.stderr)

        # restart and make sure streams are still working
        yield self.restart_arbiter()

        # wait for the process to be restarted
        res1 = yield async_poll_for(self.stdout, 'stdout')
        res2 = yield async_poll_for(self.stderr, 'stderr')
        self.assertTrue(res1)
        self.assertTrue(res2)
        yield self.stop_arbiter()
Example #30
0
    def test_stream(self):
        yield self._start_arbiter()
        # wait for the process to be started
        res1 = yield async_poll_for(self.stdout, 'stdout')
        res2 = yield async_poll_for(self.stderr, 'stderr')
        self.assertTrue(res1)
        self.assertTrue(res2)

        # clean slate
        truncate_file(self.stdout)
        truncate_file(self.stderr)

        # restart and make sure streams are still working
        yield self.restart_arbiter()

        # wait for the process to be restarted
        res1 = yield async_poll_for(self.stdout, 'stdout')
        res2 = yield async_poll_for(self.stderr, 'stderr')
        self.assertTrue(res1)
        self.assertTrue(res2)
        yield self.stop_arbiter()
Example #31
0
    def test_plugins(self):
        fd, datafile = mkstemp()
        os.close(fd)

        # setting up a circusd with a plugin
        plugin = 'circus.tests.test_arbiter.Plugin'
        plugins = [{'use': plugin, 'file': datafile}]

        yield self.start_arbiter(graceful_timeout=0, plugins=plugins,
                                 loop=get_ioloop())

        def incr_processes(cli):
            return cli.send_message('incr', name='test')

        # wait for the plugin to be started
        res = yield async_poll_for(datafile, 'PLUGIN STARTED')
        self.assertTrue(res)

        cli = AsyncCircusClient(endpoint=self.arbiter.endpoint)

        res = yield cli.send_message('list', name='test')
        self.assertEqual(len(res.get('pids')), 1)

        incr_processes(cli)
        res = yield cli.send_message('list', name='test')
        self.assertEqual(len(res.get('pids')), 2)
        # wait for the plugin to receive the signal
        res = yield async_poll_for(datafile, 'test:spawn')
        self.assertTrue(res)
        truncate_file(datafile)

        incr_processes(cli)
        res = yield cli.send_message('list', name='test')
        self.assertEqual(len(res.get('pids')), 3)

        # wait for the plugin to receive the signal
        res = yield async_poll_for(datafile, 'test:spawn')
        self.assertTrue(res)
        os.remove(datafile)
        yield self.stop_arbiter()
Example #32
0
    def test_max_age(self):
        # let's run 15 processes
        self.numprocesses('incr', name='test', nb=14)
        initial_pids = self.pids()

        # we want a max age of 2 sec.
        result = self.call('set', name='test',
                           options={'max_age': 1, 'max_age_variance': 0})

        self.assertEquals(result.get('status'), 'ok')

        # let's wait 1.2 sec.
        time.sleep(1.2)

        truncate_file(self.test_file)  # make sure we have a clean slate
        # expect at least one restart (max_age and restart), in less than 5s
        self.assertTrue(poll_for(self.test_file,
                                 ('QUITSTOPSTART', 'QUITSTART')))
        current_pids = self.pids()

        self.assertEqual(len(current_pids), 15)
        self.assertNotEqual(initial_pids, current_pids)
Example #33
0
    def test_max_age(self):
        # let's run 15 processes
        self.numprocesses('incr', name='test', nb=14)
        initial_pids = self.pids()

        # we want to make sure the watcher is really up and running 14
        # processes, and stable
        poll_for(self.test_file, 'START' * 15)
        truncate_file(self.test_file)  # make sure we have a clean slate

        # we want a max age of 1 sec.
        result = self.call('set',
                           name='test',
                           options={
                               'max_age': 1,
                               'max_age_variance': 0
                           })

        self.assertEquals(result.get('status'), 'ok')

        # we want to wait for all 15 processes to restart
        ready = False

        def _ready(olds, news):
            for pid in olds:
                if pid in news:
                    return False
            return True

        started = time.time()
        while not ready:
            if time.time() - started > 10.:
                break
            time.sleep(.1)
            ready = _ready(initial_pids, self.pids())

        current_pids = self.pids()
        self.assertEqual(len(current_pids), 15)
        self.assertNotEqual(initial_pids, current_pids)
Example #34
0
    def test_max_age(self):
        yield self.start_arbiter()
        # let's run 15 processes
        yield self.numprocesses('incr', name='test', nb=14)
        initial_pids = yield self.pids()

        # we want to make sure the watcher is really up and running 14
        # processes, and stable
        async_poll_for(self.test_file, 'START' * 15)
        truncate_file(self.test_file)  # make sure we have a clean slate

        # we want a max age of 1 sec.
        options = {'max_age': 1, 'max_age_variance': 0}
        result = yield self.call('set', name='test', waiting=True,
                                 options=options)

        self.assertEqual(result.get('status'), 'ok')

        current_pids = yield self.pids()
        self.assertEqual(len(current_pids), 15)
        self.assertNotEqual(initial_pids, current_pids)
        yield self.stop_arbiter()
Example #35
0
    def test_signal(self):
        self.assertEquals(self.numprocesses('incr', name='test'), 2)
        # wait for both to have started
        self.assertTrue(poll_for(self.test_file, 'STARTSTART'))
        truncate_file(self.test_file)

        pids = self.pids()
        self.assertEquals(len(pids), 2)
        to_kill = pids[0]
        self.assertEquals(self.status('signal', name='test', pid=to_kill,
                                      signum=signal.SIGKILL), 'ok')

        # make sure the process is restarted
        self.assertTrue(poll_for(self.test_file, 'START'))

        # we still should have two processes, but not the same pids for them
        pids = self.pids()
        count = 0
        while len(pids) < 2 and count < 10:
            pids = self.pids()
            time.sleep(.1)
        self.assertEquals(len(pids), 2)
        self.assertTrue(to_kill not in pids)