Exemple #1
0
    def test_rlimits(self):
        script_file = self.get_tmpfile(RLIMIT)
        output_file = self.get_tmpfile()

        cmd = sys.executable
        args = [script_file, output_file]
        rlimits = {"nofile": 20, "nproc": 20}

        process = Process("test", cmd, args=args, rlimits=rlimits)
        poll_for(output_file, "END")
        process.stop()

        with open(output_file, "r") as f:
            output = {}
            for line in f.readlines():
                line = line.rstrip()
                line = line.split("=", 1)
                if len(line) != 2:
                    continue
                limit, value = line
                output[limit] = value

        def srt2ints(val):
            return [circus.py3compat.long(key) for key in val[1:-1].split(",")]

        wanted = [circus.py3compat.long(20), circus.py3compat.long(20)]

        self.assertEqual(srt2ints(output["NOFILE"]), wanted)
        self.assertEqual(srt2ints(output["NPROC"]), wanted)
Exemple #2
0
    def test_rlimits(self):
        script_file = self.get_tmpfile(RLIMIT)
        output_file = self.get_tmpfile()

        cmd = PYTHON
        args = [script_file, output_file]
        rlimits = {'nofile': 20,
                   'nproc': 20}

        process = Process('test', cmd, args=args, rlimits=rlimits)
        poll_for(output_file, 'END')
        process.stop()

        with open(output_file, 'r') as f:
            output = {}
            for line in f.readlines():
                line = line.rstrip()
                line = line.split('=', 1)
                if len(line) != 2:
                    continue
                limit, value = line
                output[limit] = value

        def srt2ints(val):
            return [circus.py3compat.long(key) for key in val[1:-1].split(',')]

        wanted = [circus.py3compat.long(20), circus.py3compat.long(20)]

        self.assertEqual(srt2ints(output['NOFILE']), wanted)
        self.assertEqual(srt2ints(output['NPROC']), wanted)
Exemple #3
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)
Exemple #4
0
    def test_rlimits(self):
        script_file = self.get_tmpfile(RLIMIT)
        output_file = self.get_tmpfile()

        cmd = sys.executable
        args = [script_file, output_file]
        rlimits = {'nofile': 20,
                   'nproc': 20}

        process = Process('test', cmd, args=args, rlimits=rlimits)
        poll_for(output_file, 'END')
        process.stop()

        with open(output_file, 'r') as f:
            output = {}
            for line in f.readlines():
                line = line.rstrip()
                line = line.split('=', 1)
                if len(line) != 2:
                    continue
                limit, value = line
                output[limit] = value

        def srt2ints(val):
            return [circus.py3compat.long(key) for key in val[1:-1].split(',')]

        wanted = [circus.py3compat.long(20), circus.py3compat.long(20)]

        self.assertEqual(srt2ints(output['NOFILE']), wanted)
        self.assertEqual(srt2ints(output['NPROC']), wanted)
Exemple #5
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'))
Exemple #6
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'))
Exemple #7
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)
 def setUpClass(cls):
     dummy_process = "circus.tests.support.run_process"
     cls.stream = QueueStream()
     testfile, arbiter = cls._create_circus(dummy_process, stdout_stream={"stream": cls.stream}, debug=True)
     cls.arbiter = arbiter
     cls.test_file = testfile
     poll_for(testfile, "START")
Exemple #9
0
 def setUpClass(cls):
     dummy_process = 'circus.tests.support.run_process'
     cls.stream = QueueStream()
     testfile, arbiter = cls._create_circus(
         dummy_process, stdout_stream={'stream': cls.stream}, debug=True)
     cls.arbiter = arbiter
     cls.test_file = testfile
     poll_for(testfile, 'START')
Exemple #10
0
 def setUpClass(cls):
     dummy_process = 'circus.tests.support.run_process'
     cls.stream = QueueStream()
     testfile, arbiter = cls._create_circus(
         dummy_process, stdout_stream={'stream': cls.stream})
     cls.arbiter = arbiter
     cls.test_file = testfile
     poll_for(testfile, 'START')
    def test_watchdog_discovery_not_found(self):
        yield self.start_arbiter(fqn)
        poll_for(self.test_file, 'START')

        config = {'loop_rate': 0.1, 'watchers_regex': "^foo.*$"}
        with warnings.catch_warnings():
            pid_status = yield async_run_plugin(WatchDog, config,
                                                get_pid_status)
        self.assertEqual(len(pid_status), 0, pid_status)
        yield self.stop_arbiter()
    def test_watchdog_discovery_not_found(self):
        yield self.start_arbiter(fqn)
        poll_for(self.test_file, 'START')

        config = {'loop_rate': 0.1, 'watchers_regex': "^foo.*$"}
        with warnings.catch_warnings():
            pid_status = yield async_run_plugin(WatchDog, config,
                                                get_pid_status)
        self.assertEqual(len(pid_status), 0, pid_status)
        yield self.stop_arbiter()
Exemple #13
0
    def test_handler(self):
        yield self.start_arbiter()

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

        # stopping...
        yield self.arbiter.stop()

        # wait for the process to be stopped
        self.assertTrue(poll_for(self.test_file, 'QUIT'))
Exemple #14
0
    def test_handler(self):
        yield self.start_arbiter()

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

        # stopping...
        yield self.arbiter.stop()

        # wait for the process to be stopped
        self.assertTrue(poll_for(self.test_file, 'QUIT'))
Exemple #15
0
    def test_handler(self):
        test_file = self._run_circus('circus.tests.support.run_process')

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

        # stopping...
        self._stop_runners()

        # wait for the process to be stopped
        self.assertTrue(poll_for(test_file, 'QUIT'))
Exemple #16
0
    def test_add_start(self):
        yield self.start_arbiter()
        poll_for(self.test_file, 'START')

        stdout, stderr = yield async_run_ctl('add --start test2 "sleep 1"')
        self.assertEqual(stderr, '')
        self.assertEqual(stdout, 'ok\n')
        stdout, stderr = yield async_run_ctl('status test2')
        self.assertEqual(stderr, '')
        self.assertEqual(stdout, 'active\n')
        yield self.stop_arbiter()
    def test_handler(self):
        test_file = self._run_circus(
            'circus.tests.support.run_process')

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

        # stopping...
        self._stop_runners()

        # wait for the process to be stopped
        self.assertTrue(poll_for(test_file, 'QUIT'))
    def test_resource_watcher_max_cpu(self):
        yield self.start_arbiter(fqn)
        poll_for(self.test_file, 'START')
        config = {'loop_rate': 0.1, 'max_cpu': 0.1, 'watcher': 'test'}

        statsd_increments = yield async_run_plugin(ResourceWatcher,
                                                   config,
                                                   get_statsd_increments)

        self._check_statsd(statsd_increments,
                           '_resource_watcher.test.over_cpu')
        yield self.stop_arbiter()
Exemple #19
0
    def test_resource_watcher_max_cpu(self):
        yield self.start_arbiter(fqn)
        poll_for(self.test_file, 'START')
        config = {'loop_rate': 0.1, 'max_cpu': 0.1, 'watcher': 'test'}

        statsd_increments = yield async_run_plugin(ResourceWatcher,
                                                   config,
                                                   get_statsd_increments)

        self._check_statsd(statsd_increments,
                           '_resource_watcher.test.over_cpu')
        yield self.stop_arbiter()
Exemple #20
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'))
Exemple #21
0
    def test_launch_cli(self):
        yield self.start_arbiter()
        poll_for(self.test_file, 'START')

        stdout, stderr = yield self.run_ctl()
        self.assertEqual(stderr, '')
        output = stdout.splitlines()
        self.assertEqual(output[0], VERSION)
        # strip of term escape characters, if any
        prompt = output[2][-len(CircusCtl.prompt):]
        self.assertEqual(prompt, CircusCtl.prompt)

        yield self.stop_arbiter()
Exemple #22
0
    def setUpClass(cls):
        dummy_process = 'circus.tests.test_stream.run_process'
        fd, cls.stdout = tempfile.mkstemp()
        os.close(fd)
        fd, cls.stderr = tempfile.mkstemp()
        os.close(fd)
        stdout = {'stream': FileStream(cls.stdout)}
        stderr = {'stream': FileStream(cls.stderr)}
        cls.file, cls.arbiter = cls._create_circus(dummy_process,
                                                   stdout_stream=stdout,
                                                   stderr_stream=stderr,
                                                   debug=True)

        poll_for(cls.file, 'START')
Exemple #23
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'))
Exemple #24
0
    def setUpClass(cls):
        dummy_process = 'circus.tests.test_stream.run_process'
        fd, cls.stdout = tempfile.mkstemp()
        os.close(fd)
        fd, cls.stderr = tempfile.mkstemp()
        os.close(fd)
        stdout = {'stream': FileStream(cls.stdout)}
        stderr = {'stream': FileStream(cls.stderr)}
        cls.file, cls.arbiter = cls._create_circus(dummy_process,
                                                   stdout_stream=stdout,
                                                   stderr_stream=stderr,
                                                   debug=True)

        poll_for(cls.file, 'START')
Exemple #25
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"))
Exemple #26
0
    def test_reload1(self):
        self.assertTrue(poll_for(self.test_file, 'START'))  # process started
        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)
Exemple #27
0
    def test_reload1(self):
        self.assertTrue(poll_for(self.test_file, 'START'))  # process started
        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)
Exemple #28
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)
Exemple #29
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'))
Exemple #30
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)
    def test_full_stats(self):
        dummy_process = 'circus.tests.support.run_process'
        yield self.start_arbiter(dummy_process)
        poll_for(self.test_file, 'START')

        config = {'loop_rate': 0.2}
        gauges = yield async_run_plugin(
            FullStats, config,
            plugin_info_callback=get_gauges,
            duration=1000)

        # we should have a bunch of stats events here
        self.assertTrue(len(gauges) >= 5)
        last_batch = [name for name, value in gauges[-5:]]
        last_batch.sort()
        wanted = ['_stats.test.cpu_max', '_stats.test.cpu_sum',
                  '_stats.test.mem_max', '_stats.test.mem_sum',
                  '_stats.test.watchers_num']
        self.assertEqual(last_batch, wanted)
        yield self.stop_arbiter()
Exemple #32
0
    def test_full_stats(self):
        dummy_process = 'circus.tests.support.run_process'
        yield self.start_arbiter(dummy_process)
        poll_for(self.test_file, 'START')

        config = {'loop_rate': 0.2}
        gauges = yield async_run_plugin(
            FullStats, config,
            plugin_info_callback=get_gauges,
            duration=1000)

        # we should have a bunch of stats events here
        self.assertTrue(len(gauges) >= 5)
        last_batch = sorted(name for name, value in gauges[-5:])
        wanted = ['_stats.test.cpu_max', '_stats.test.cpu_sum',
                  '_stats.test.mem_max', '_stats.test.mem_sum',
                  '_stats.test.watchers_num']
        self.assertEqual(last_batch, wanted)

        yield self.stop_arbiter()
Exemple #33
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)
Exemple #34
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)
Exemple #35
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)
Exemple #36
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)
Exemple #37
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)
Exemple #38
0
    def test_streams(self):
        script_file = self.get_tmpfile(VERBOSE)
        output_file = self.get_tmpfile()

        cmd = PYTHON
        args = [script_file, output_file]

        # 1. streams sent to /dev/null
        process = Process('test',
                          1,
                          cmd,
                          args=args,
                          close_child_stdout=True,
                          close_child_stderr=True)
        try:
            poll_for(output_file, 'END')

            # the pipes should be empty
            self.assertEqual(process.stdout.read(), b'')
            self.assertEqual(process.stderr.read(), b'')
        finally:
            process.stop()

        # 2. streams sent to /dev/null, no PIPEs
        output_file = self.get_tmpfile()
        args[1] = output_file

        process = Process('test',
                          1,
                          cmd,
                          args=args,
                          close_child_stdout=True,
                          close_child_stderr=True,
                          pipe_stdout=False,
                          pipe_stderr=False)

        try:
            poll_for(output_file, 'END')
            # the pipes should be unexistant
            self.assertTrue(process.stdout is None)
            self.assertTrue(process.stderr is None)
        finally:
            process.stop()

        # 3. streams & pipes open
        output_file = self.get_tmpfile()
        args[1] = output_file
        process = Process('test', '1', cmd, args=args)

        try:
            poll_for(output_file, 'END')

            # the pipes should be unexistant
            self.assertEqual(len(process.stdout.read()), 2890)
            self.assertEqual(len(process.stderr.read()), 2890)
        finally:
            process.stop()
Exemple #39
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(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()
Exemple #40
0
    def test_streams(self):
        script_file = self.get_tmpfile(VERBOSE)
        output_file = self.get_tmpfile()

        cmd = sys.executable
        args = [script_file, output_file]

        # 1. streams sent to /dev/null
        process = Process("test", cmd, args=args, close_child_stdout=True, close_child_stderr=True)
        try:
            poll_for(output_file, "END")

            # the pipes should be empty
            self.assertEqual(process.stdout.read(), b"")
            self.assertEqual(process.stderr.read(), b"")
        finally:
            process.stop()

        # 2. streams sent to /dev/null, no PIPEs
        output_file = self.get_tmpfile()
        args[1] = output_file

        process = Process(
            "test",
            cmd,
            args=args,
            close_child_stdout=True,
            close_child_stderr=True,
            pipe_stdout=False,
            pipe_stderr=False,
        )

        try:
            poll_for(output_file, "END")
            # the pipes should be unexistant
            self.assertTrue(process.stdout is None)
            self.assertTrue(process.stderr is None)
        finally:
            process.stop()

        # 3. streams & pipes open
        output_file = self.get_tmpfile()
        args[1] = output_file
        process = Process("test", cmd, args=args)

        try:
            poll_for(output_file, "END")

            # the pipes should be unexistant
            self.assertEqual(len(process.stdout.read()), 2890)
            self.assertEqual(len(process.stderr.read()), 2890)
        finally:
            process.stop()
Exemple #41
0
    def test_reload1(self):
        yield self.start_arbiter(graceful_timeout=0)
        name = 'test_reload1'
        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")
        self.assertTrue(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()
Exemple #42
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)
Exemple #43
0
 def setUp(self):
     super(TestTrainer, self).setUp()
     dummy_process = 'circus.tests.support.run_process'
     self.test_file = self._run_circus(dummy_process)
     poll_for(self.test_file, 'START')
Exemple #44
0
 def setUp(self):
     super(TestTrainer, self).setUp()
     dummy_process = 'circus.tests.support.run_process'
     self.test_file = self._run_circus(dummy_process)
     poll_for(self.test_file, 'START')
Exemple #45
0
 def test_dummy(self):
     yield self.start_arbiter('circus.tests.test_runner.Dummy')
     self.assertTrue(poll_for(self.test_file, '..........'))
     yield self.stop_arbiter()
Exemple #46
0
 def test_dummy(self):
     yield self.start_arbiter('circus.tests.test_runner.Dummy')
     self.assertTrue(poll_for(self.test_file, '..........'))
     yield self.stop_arbiter()
Exemple #47
0
 def setUp(self):
     super(CLITest, self).setUp()
     test_file = self._run_circus('circus.tests.support.run_process')
     poll_for(test_file, 'START')
 def setUpClass(cls):
     dummy_process = "circus.tests.test_plugin_resource_watcher.run_leaky"
     cls.file, cls.arbiter = cls._create_circus(dummy_process)
     poll_for(cls.file, "START")
Exemple #49
0
 def test_dummy(self):
     test_file = self._run_circus('circus.tests.test_runner.Dummy')
     self.assertTrue(poll_for(test_file, '..........'))
 def setUp(self):
     super(TestResourceWatcher, self).setUp()
     dummy_process = 'circus.tests.test_plugin_resource_watcher.run_leaky'
     self.test_file = self._run_circus(dummy_process)
     poll_for(self.test_file, 'START')
Exemple #51
0
 def test_dummy(self):
     test_file = self._run_circus('circus.tests.test_runner.Dummy')
     self.assertTrue(poll_for(test_file, '..........'))
Exemple #52
0
 def setUp(self):
     super(TestPluginWatchDog, self).setUp()
     self.test_file = self._run_circus(fqn)
     poll_for(self.test_file, 'START')
Exemple #53
0
 def setUp(self):
     super(CLITest, self).setUp()
     test_file = self._run_circus('circus.tests.support.run_process')
     poll_for(test_file, 'START')
Exemple #54
0
 def setUp(self):
     super(TestPluginWatchDog, self).setUp()
     self.test_file = self._run_circus(fqn)
     poll_for(self.test_file, 'START')
Exemple #55
0
 def setUpClass(cls):
     dummy_process = 'circus.tests.test_plugin_resource_watcher.run_leaky'
     cls.file, cls.arbiter = cls._create_circus(dummy_process)
     poll_for(cls.file, 'START')