Ejemplo n.º 1
0
    def test_sending_crap_ujson(self):
        test_dir = self._get_dir()
        os.chdir(os.path.dirname(__file__))

        data = StringIO()
        filepath = 'test_here.py'
        zf = zipfile.ZipFile(data, "w", compression=zipfile.ZIP_DEFLATED)
        info = zipfile.ZipInfo('test_here.py')
        info.external_attr = os.stat(filepath).st_mode << 16L

        with open(filepath) as f:
            zf.writestr(info, f.read())

        zf.close()
        data = data.getvalue()

        args = get_runner_args(
            fqn='test_here.TestWebSite.test_something',
            agents=1,
            users=1,
            hits=1,
            test_dir=test_dir,
            include_file=['test_here.py'])

        args['crap'] = data
        self.assertRaises(ValueError, start_runner, args)
Ejemplo n.º 2
0
    def test_sending_crap_ujson(self):
        test_dir = self._get_dir()
        os.chdir(os.path.dirname(__file__))

        data = StringIO()
        filepath = 'test_here.py'
        zf = zipfile.ZipFile(data, "w", compression=zipfile.ZIP_DEFLATED)
        info = zipfile.ZipInfo('test_here.py')
        info.external_attr = os.stat(filepath).st_mode << 16L

        with open(filepath) as f:
            zf.writestr(info, f.read())

        zf.close()
        data = data.getvalue()

        args = get_runner_args(
            fqn='test_here.TestWebSite.test_something',
            agents=1,
            users=1,
            hits=1,
            test_dir=test_dir,
            include_file=['test_here.py'])

        args['crap'] = data
        self.assertRaises(ValueError, start_runner, args)
Ejemplo n.º 3
0
 def test_duration_updates_counters(self):
     runner = LocalRunner(get_runner_args(
         fqn='loads.examples.test_blog.TestWebSite.test_concurrency',
         output=['null'], duration=2.))
     runner.execute()
     nb_success = runner.test_result.nb_success
     assert nb_success > 2, nb_success
Ejemplo n.º 4
0
    def test_distributed_run(self):
        start_runner(get_runner_args(
            fqn='loads.examples.test_blog.TestWebSite.test_something',
            agents=2,
            project_name='test_distributed_run',
            output=['null'],
            observer=['loads.tests.test_functional.observer',
                      'loads.tests.test_functional.observer_fail'],
            users=1, hits=5))

        client = Pool()
        runs = client.list_runs()
        run_id = runs.keys()[0]
        client.stop_run(run_id)

        # checking the metadata
        metadata = client.get_metadata(run_id)
        self.assertEqual(metadata['project_name'], 'test_distributed_run')

        # checking the data
        data = client.get_data(run_id)
        self.assertTrue(len(data) > 25, len(data))
        self.assertEqual(client.get_urls(run_id),
                         {u'http://127.0.0.1:9000/': 10})
        counts = dict(client.get_counts(run_id))
        self.assertEquals(counts['socket_open'], 10)
        self.assertEquals(counts['socket_close'], 10)

        # making sure the observer was called
        with open(_RESULTS) as f:
            data = f.readlines()

        assert len(data) > 0, data
Ejemplo n.º 5
0
    def test_file_copy_test_file(self):
        test_dir = self._get_dir()
        os.chdir(os.path.dirname(__file__))

        args = get_runner_args(
            fqn='test_here.TestWebSite.test_something',
            agents=1,
            users=1,
            hits=1,
            test_dir=test_dir,
            include_file=['test_here.py'])

        start_runner(args)
        data = []

        for i in range(20):
            runs = self.client.list_runs()
            if len(runs) == 0:
                time.sleep(.1)
                continue
            try:
                data = self.client.get_data(runs.keys()[0])
            except Exception:
                raise AssertionError(str(runs))

            if len(data) > 0:
                break
            time.sleep(.1)

        # check that we got in the dir
        content = os.listdir(test_dir)
        self.assertTrue('test_here.py' in content, content)

        if data == []:
            raise AssertionError('No data back')
Ejemplo n.º 6
0
    def test_errors(self):
        client = self._get_client()

        start_runner(
            get_runner_args(
                fqn='loads.examples.test_blog.TestWebSite.test_will_error',
                agents=1,
                project_name='test_distributed_run',
                output=['null'],
                observer=[
                    'loads.tests.test_functional.Observer',
                    'loads.tests.test_functional.ObserverFail'
                ],
                users=1,
                hits=5))
        run_id, _ = self._wait_run_started(client)
        client.stop_run(run_id)

        # checking the metadata
        metadata = client.get_metadata(run_id)
        self.assertEqual(metadata['project_name'], 'test_distributed_run')

        # checking the data
        # the run is over so the detailed lines where pruned
        # but we have all errors
        errors = list(self.db.get_errors(run_id))
        self.assertTrue(len(errors) > 0)
Ejemplo n.º 7
0
 def test_duration_updates_counters(self):
     runner = LocalRunner(get_runner_args(
         fqn='loads.examples.test_blog.TestWebSite.test_concurrency',
         output=['null'], duration=2.))
     runner.execute()
     nb_success = runner.test_result.nb_success
     assert nb_success > 2, nb_success
Ejemplo n.º 8
0
    def test_distributed_run(self):
        start_runner(
            get_runner_args(
                fqn="loads.examples.test_blog.TestWebSite.test_something",
                agents=2,
                project_name="test_distributed_run",
                output=["null"],
                observer=["loads.tests.test_functional.observer", "loads.tests.test_functional.observer_fail"],
                users=1,
                hits=5,
            )
        )

        client = Pool()
        runs = client.list_runs()
        run_id = runs.keys()[0]
        client.stop_run(run_id)

        # checking the metadata
        metadata = client.get_metadata(run_id)
        self.assertEqual(metadata["project_name"], "test_distributed_run")

        # checking the data
        data = client.get_data(run_id)
        self.assertTrue(len(data) > 25, len(data))
        self.assertEqual(client.get_urls(run_id), {u"http://127.0.0.1:9000/": 10})
        counts = dict(client.get_counts(run_id))
        self.assertEquals(counts["socket_open"], 10)
        self.assertEquals(counts["socket_close"], 10)

        # making sure the observer was called
        with open(_RESULTS) as f:
            data = f.readlines()

        assert len(data) > 0, data
Ejemplo n.º 9
0
    def test_file_copy_test_file(self):
        client = self._get_client()
        test_dir = self._get_dir()
        os.chdir(os.path.dirname(__file__))

        args = get_runner_args(fqn='test_here.TestWebSite.test_something',
                               agents=1,
                               users=1,
                               hits=1,
                               test_dir=test_dir,
                               include_file=['test_here.py'])

        start_runner(args)
        data = []

        run_id, agents = self._wait_run_started(client)
        self._wait_run_over(client)
        data = self.client.get_metadata(run_id)

        # check that we got in the dir
        real_test_dir = test_dir + agents[0][0]
        self.dirs.append(real_test_dir)
        content = os.listdir(real_test_dir)
        self.assertTrue('test_here.py' in content, content)

        if data == []:
            raise AssertionError('No data back')
Ejemplo n.º 10
0
    def test_distributed_run(self):
        start_runner(get_runner_args(
            fqn='loads.examples.test_blog.TestWebSite.test_something',
            agents=2,
            project_name='test_distributed_run',
            output=['null'],
            observer=['loads.tests.test_functional.Observer',
                      'loads.tests.test_functional.ObserverFail'],
            users=1, hits=5))

        client = Pool()
        runs = client.list_runs()
        run_id = runs.keys()[0]
        client.stop_run(run_id)

        # checking the metadata
        metadata = client.get_metadata(run_id)
        self.assertEqual(metadata['project_name'], 'test_distributed_run')

        # checking the data
        # the run is over so the detailed lines where pruned
        self.assertRaises(ValueError, client.get_data, run_id)
        self.assertEqual(client.get_urls(run_id),
                         {u'http://127.0.0.1:9000/': 10})
        counts = dict(client.get_counts(run_id))
        self.assertEquals(counts['socket_open'], 10)
        self.assertEquals(counts['socket_close'], 10)

        # making sure the observer was called
        with open(_RESULTS) as f:
            data = f.readlines()

        assert len(data) > 0, data
Ejemplo n.º 11
0
    def test_file_copy_test_file(self):
        test_dir = self._get_dir()
        os.chdir(os.path.dirname(__file__))

        args = get_runner_args(
            fqn='test_here.TestWebSite.test_something',
            agents=1,
            users=1,
            hits=1,
            test_dir=test_dir,
            include_file=['test_here.py'])

        start_runner(args)
        data = []

        for i in range(20):
            runs = self.client.list_runs()
            if len(runs) == 0:
                time.sleep(.1)
                continue
            try:
                data = self.client.get_data(runs.keys()[-1])
            except Exception:
                raise AssertionError(str(runs))

            if len(data) > 0:
                break
            time.sleep(.1)

        # check that we got in the dir
        content = os.listdir(test_dir)
        self.assertTrue('test_here.py' in content, content)

        if data == []:
            raise AssertionError('No data back')
Ejemplo n.º 12
0
 def test_normal_run_with_users_and_hits(self):
     start_runner(
         get_runner_args(
             fqn='loads.examples.test_blog.TestWebSite.test_something',
             output=['null'],
             users=2,
             hits=2))
Ejemplo n.º 13
0
    def test_file_copy_test_file(self):
        client = self._get_client()
        test_dir = self._get_dir()
        os.chdir(os.path.dirname(__file__))

        args = get_runner_args(
            fqn='test_here.TestWebSite.test_something',
            agents=1,
            users=1,
            hits=1,
            test_dir=test_dir,
            include_file=['test_here.py'])

        start_runner(args)
        data = []

        run_id, agents = self._wait_run_started(client)
        self._wait_run_over(client)
        data = self.client.get_metadata(run_id)

        # check that we got in the dir
        real_test_dir = test_dir + agents[0][0]
        self.dirs.append(real_test_dir)
        content = os.listdir(real_test_dir)
        self.assertTrue('test_here.py' in content, content)

        if data == []:
            raise AssertionError('No data back')
Ejemplo n.º 14
0
    def test_distributed_run(self):
        start_runner(get_runner_args(
            fqn='loads.examples.test_blog.TestWebSite.test_something',
            agents=2,
            output=['null'],
            observer=['loads.tests.test_functional.observer',
                      'loads.tests.test_functional.observer_fail'],
            users=1, hits=5))

        client = Pool()
        runs = client.list_runs()
        run_id = runs.keys()[0]
        client.stop_run(run_id)

        # checking the data
        data = client.get_data(run_id)
        self.assertTrue(len(data) > 25, len(data))
        self.assertEqual(client.get_urls(run_id),
                         {u'http://127.0.0.1:9000/': 10})
        counts = dict(client.get_counts(run_id))
        self.assertEquals(counts['socket_open'], 10)
        #self.assertEquals(counts['socket_close'], 10)  XXX TO BE FIXED

        # making sure the observer was called
        with open(_RESULTS) as f:
            data = f.readlines()

        assert len(data) > 0, data
Ejemplo n.º 15
0
 def test_concurent_session_access(self):
     runner = Runner(get_runner_args(
         fqn='loads.examples.test_blog.TestWebSite.test_concurrency',
         output=['null'], users=10))
     runner.execute()
     assert runner.test_result.nb_success == 10
     assert runner.test_result.nb_errors == 0
     assert runner.test_result.nb_failures == 0
Ejemplo n.º 16
0
 def test_file_output(self):
     fqn = 'loads.examples.test_blog.TestWebSite.test_something'
     args = get_runner_args(fqn=fqn, output=['file'])
     fd, args['output_file_filename'] = tempfile.mkstemp()
     os.close(fd)
     try:
         start_runner(args)
     finally:
         os.remove(args['output_file_filename'])
Ejemplo n.º 17
0
 def test_file_output(self):
     fqn = 'loads.examples.test_blog.TestWebSite.test_something'
     args = get_runner_args(fqn=fqn, output=['file'])
     fd, args['output_file_filename'] = tempfile.mkstemp()
     os.close(fd)
     try:
         start_runner(args)
     finally:
         os.remove(args['output_file_filename'])
Ejemplo n.º 18
0
def main():
    fqn = sys.argv[1]
    status = os.environ['LOADS_STATUS'].split(',')
    args = get_runner_args(fqn=fqn,
                           zmq_endpoint=os.environ['LOADS_ZMQ_RECEIVER'],
                           agent_id=os.environ['LOADS_AGENT_ID'],
                           run_id=os.environ['LOADS_RUN_ID'],
                           loads_status=status, slave=True)
    Runner(args).execute()
Ejemplo n.º 19
0
    def test_distributed_run(self):
        start_runner(get_runner_args(
            fqn='loads.examples.test_blog.TestWebSite.test_something',
            agents=2,
            output=['null'],
            users=1, cycles=10))

        runs = self.client.list_runs()
        data = self.client.get_data(runs.keys()[0])
        self.assertTrue(len(data) > 100)
Ejemplo n.º 20
0
 def test_concurent_session_access(self):
     runner = LocalRunner(get_runner_args(
         fqn='loads.examples.test_blog.TestWebSite.test_concurrency',
         output=['null'], users=2))
     runner.execute()
     nb_success = runner.test_result.nb_success
     assert nb_success == 2, nb_success
     assert runner.test_result.nb_errors == 0
     assert runner.test_result.nb_failures == 0
     assert runner.test_result.get_counter('lavabo') == 2
     assert runner.test_result.get_counter('beau') == 2
Ejemplo n.º 21
0
def main():
    fqn = sys.argv[1]
    status = os.environ['LOADS_STATUS'].split(',')
    args = get_runner_args(fqn=fqn,
                           zmq_endpoint=os.environ['LOADS_ZMQ_RECEIVER'],
                           agent_id=os.environ['LOADS_AGENT_ID'],
                           run_id=os.environ['LOADS_RUN_ID'],
                           externally_managed=True,
                           loads_status=status,
                           slave=True)
    LocalRunner(args).execute()
Ejemplo n.º 22
0
 def test_concurent_session_access(self):
     runner = LocalRunner(get_runner_args(
         fqn='loads.examples.test_blog.TestWebSite.test_concurrency',
         output=['null'], users=2))
     runner.execute()
     nb_success = runner.test_result.nb_success
     assert nb_success == 2, nb_success
     assert runner.test_result.nb_errors == 0
     assert runner.test_result.nb_failures == 0
     assert runner.test_result.get_counter('lavabo') == 2
     assert runner.test_result.get_counter('beau') == 2
Ejemplo n.º 23
0
    def test_distributed_run_external_runner(self):
        args = get_runner_args(
            fqn='loads.examples.test_blog.TestWebSite.test_something',
            agents=1,
            users=1,
            test_runner='%s -m loads.tests.runner {test}' % sys.executable)

        start_runner(args)
        client = Pool()
        runs = client.list_runs()
        data = client.get_metadata(runs.keys()[0])
        self.assertTrue(len(data) > 5, len(data))
Ejemplo n.º 24
0
    def test_distributed_run_external_runner(self):
        args = get_runner_args(
            fqn='loads.examples.test_blog.TestWebSite.test_something',
            agents=1,
            users=1,
            test_runner='%s -m loads.tests.runner {test}' % sys.executable)

        start_runner(args)
        client = Pool()
        runs = client.list_runs()
        data = client.get_data(runs.keys()[0])
        self.assertTrue(len(data) > 5, len(data))
Ejemplo n.º 25
0
    def test_concurrency_duration(self):
        runner = LocalRunner(get_runner_args(
            fqn='loads.examples.test_blog.TestWebSite.test_sleep',
            output=['null'],
            agents=1,
            users=1,
            duration=2,
            concurrency=5
        ))
        runner.execute()

        rps = runner.test_result.requests_per_second()

        assert 14 < rps < 16
Ejemplo n.º 26
0
    def test_concurrency_duration(self):
        runner = LocalRunner(
            get_runner_args(
                fqn="loads.examples.test_blog.TestWebSite.test_sleep",
                output=["null"],
                agents=1,
                users=1,
                duration=2,
                concurrency=5,
            )
        )
        runner.execute()

        rps = runner.test_result.requests_per_second()

        assert 14 < rps < 16
Ejemplo n.º 27
0
    def test_distributed_run_duration(self):
        args = get_runner_args(
            fqn='loads.examples.test_blog.TestWebSite.test_something',
            agents=1,
            #output=['null'],
            users=10,
            duration=1)

        start_runner(args)
        time.sleep(1.)
        runs = self.client.list_runs()
        try:
            data = self.client.get_data(runs.keys()[0])
        except Exception:
            data = self.client.get_data(runs.keys()[0])
        self.assertTrue(len(data) > 10)
Ejemplo n.º 28
0
    def test_distributed_detach(self):
        client = self._get_client()

        args = get_runner_args(
            fqn='loads.examples.test_blog.TestWebSite.test_something',
            agents=1,
            users=1,
            output=['null'],
            duration=2)

        # simulate a ctrl+c
        def _recv(self, msg):
            raise KeyboardInterrupt

        old = DistributedRunner._recv_result
        DistributedRunner._recv_result = _recv

        # simulate a 'detach' answer
        def _raw_input(msg):
            return 'detach'

        from loads import main
        main.raw_input = _raw_input

        # start the runner
        start_runner(args)

        # getting the run_id
        run_id, _ = self._wait_run_started()

        # we detached.
        time.sleep(.2)

        # now reattach the console
        DistributedRunner._recv_result = old
        start_runner({
            'attach': True,
            'broker': DEFAULT_FRONTEND,
            'output': ['null']
        })

        # now waiting for the test to be over
        self._wait_run_over(client)

        # now let's see the metadata
        data = client.get_metadata(run_id)
        self.assertTrue(len(data) > 5, len(data))
Ejemplo n.º 29
0
    def test_distributed_detach(self):
        time.sleep(.5)

        args = get_runner_args(
            fqn='loads.examples.test_blog.TestWebSite.test_something',
            agents=1,
            users=1,
            output=['null'],
            duration=2)

        # simulate a ctrl+c
        def _recv(self, msg):
            raise KeyboardInterrupt

        old = DistributedRunner._recv_result
        DistributedRunner._recv_result = _recv

        # simulate a 'detach' answer
        def _raw_input(msg):
            return 'detach'

        from loads import main
        main.raw_input = _raw_input

        # start the runner
        start_runner(args)
        # we detached.
        time.sleep(.2)

        # now reattach the console
        DistributedRunner._recv_result = old
        start_runner({
            'attach': True,
            'broker': DEFAULT_FRONTEND,
            'output': ['null']
        })

        # the test is over
        for i in range(5):
            time.sleep(.1)
            runs = self.client.list_runs()
            if len(runs) == 0:
                continue
            data = self.client.get_data(runs.keys()[0])
            if len(data) > 0:
                return
        raise AssertionError('No data back')
Ejemplo n.º 30
0
    def test_distributed_run_duration(self):
        args = get_runner_args(
            fqn="loads.examples.test_blog.TestWebSite.test_something", agents=1, output=["null"], users=1, duration=2
        )

        start_runner(args)

        client = Pool()

        for i in range(10):
            runs = client.list_runs()
            time.sleep(0.1)
            data = client.get_data(runs.keys()[0])
            if len(data) > 0:
                return

        raise AssertionError("No data back")
Ejemplo n.º 31
0
def main():
    fqn = sys.argv[1]
    status = [
        os.environ.get('LOADS_TOTAL_HITS', '1'),
        os.environ.get('LOADS_TOTAL_USERS', '1'),
        os.environ.get('LOADS_CURRENT_HIT', '1'),
        os.environ.get('LOADS_CURRENT_USER', '1'),
    ]
    args = get_runner_args(fqn=fqn,
                           hits=os.environ.get('LOADS_TOTAL_HITS'),
                           duration=os.environ.get('LOADS_DURATION'),
                           zmq_endpoint=os.environ['LOADS_ZMQ_RECEIVER'],
                           agent_id=os.environ['LOADS_AGENT_ID'],
                           run_id=os.environ['LOADS_RUN_ID'],
                           externally_managed=True,
                           loads_status=status, slave=True)
    LocalRunner(args).execute()
Ejemplo n.º 32
0
def main():
    fqn = sys.argv[1]
    status = [
        os.environ.get('LOADS_TOTAL_HITS', '1'),
        os.environ.get('LOADS_TOTAL_USERS', '1'),
        os.environ.get('LOADS_CURRENT_HIT', '1'),
        os.environ.get('LOADS_CURRENT_USER', '1'),
    ]
    args = get_runner_args(fqn=fqn,
                           hits=os.environ.get('LOADS_TOTAL_HITS'),
                           duration=os.environ.get('LOADS_DURATION'),
                           zmq_endpoint=os.environ['LOADS_ZMQ_RECEIVER'],
                           agent_id=os.environ['LOADS_AGENT_ID'],
                           run_id=os.environ['LOADS_RUN_ID'],
                           externally_managed=True,
                           loads_status=status,
                           slave=True)
    LocalRunner(args).execute()
Ejemplo n.º 33
0
    def test_distributed_detach(self):
        time.sleep(.5)

        args = get_runner_args(
            fqn='loads.examples.test_blog.TestWebSite.test_something',
            agents=1,
            users=1,
            output=['null'],
            duration=2)

        # simulate a ctrl+c
        def _recv(self, msg):
            raise KeyboardInterrupt

        old = DistributedRunner._recv_result
        DistributedRunner._recv_result = _recv

        # simulate a 'detach' answer
        def _raw_input(msg):
            return 'detach'

        from loads import main
        main.raw_input = _raw_input

        # start the runner
        start_runner(args)
        # we detached.
        time.sleep(.2)

        # now reattach the console
        DistributedRunner._recv_result = old
        start_runner({'attach': True, 'broker': DEFAULT_FRONTEND,
                      'output': ['null']})

        # the test is over
        for i in range(5):
            time.sleep(.1)
            runs = self.client.list_runs()
            if len(runs) == 0:
                continue
            data = self.client.get_data(runs.keys()[0])
            if len(data) > 0:
                return
        raise AssertionError('No data back')
Ejemplo n.º 34
0
    def test_distributed_detach(self):
        client = self._get_client()

        args = get_runner_args(
            fqn='loads.examples.test_blog.TestWebSite.test_something',
            agents=1,
            users=1,
            output=['null'],
            duration=2)

        # simulate a ctrl+c
        def _recv(self, msg):
            raise KeyboardInterrupt

        old = DistributedRunner._recv_result
        DistributedRunner._recv_result = _recv

        # simulate a 'detach' answer
        def _raw_input(msg):
            return 'detach'

        from loads import main
        main.raw_input = _raw_input

        # start the runner
        start_runner(args)

        # getting the run_id
        run_id, _ = self._wait_run_started()

        # we detached.
        time.sleep(.2)

        # now reattach the console
        DistributedRunner._recv_result = old
        start_runner({'attach': True, 'broker': DEFAULT_FRONTEND,
                      'output': ['null']})

        # now waiting for the test to be over
        self._wait_run_over(client)

        # now let's see the metadata
        data = client.get_metadata(run_id)
        self.assertTrue(len(data) > 5, len(data))
Ejemplo n.º 35
0
    def test_distributed_run_external_runner(self):
        client = self._get_client()

        args = get_runner_args(
            fqn='loads.examples.test_blog.TestWebSite.test_something',
            agents=1,
            users=1,
            test_runner='%s -m loads.tests.runner {test}' % sys.executable)

        start_runner(args)

        # getting the run_id
        runs = self.client.list_runs()
        while runs == []:
            runs = self.client.list_runs()
        run_id = runs.keys()[0]

        data = client.get_metadata(run_id)
        self.assertTrue(len(data) > 5, len(data))
Ejemplo n.º 36
0
    def test_distributed_run_external_runner(self):
        client = self._get_client()

        args = get_runner_args(
            fqn='loads.examples.test_blog.TestWebSite.test_something',
            agents=1,
            users=1,
            test_runner='%s -m loads.tests.runner {test}' % sys.executable)

        start_runner(args)

        # getting the run_id
        runs = self.client.list_runs()
        while runs == []:
            runs = self.client.list_runs()
        run_id = runs.keys()[0]

        data = client.get_metadata(run_id)
        self.assertTrue(len(data) > 5, len(data))
Ejemplo n.º 37
0
    def test_distributed_run_duration(self):
        args = get_runner_args(
            fqn='loads.examples.test_blog.TestWebSite.test_something',
            agents=1,
            output=['null'],
            users=1,
            duration=2)

        start_runner(args)

        client = Pool()

        for i in range(10):
            runs = client.list_runs()
            time.sleep(.1)
            data = client.get_data(runs.keys()[0])
            if len(data) > 0:
                return

        raise AssertionError('No data back')
Ejemplo n.º 38
0
    def test_distributed_run_duration(self):
        client = self._get_client()

        args = get_runner_args(
            fqn='loads.examples.test_blog.TestWebSite.test_something',
            agents=1,
            output=['null'],
            users=1,
            duration=2)

        start_runner(args)

        for i in range(10):
            runs = client.list_runs()
            time.sleep(.1)
            data = client.get_metadata(runs.keys()[0])
            if len(data) > 0:
                return

        raise AssertionError('No data back')
Ejemplo n.º 39
0
    def test_distributed_run(self):
        client = self._get_client()

        start_runner(
            get_runner_args(
                fqn='loads.examples.test_blog.TestWebSite.test_something',
                agents=2,
                project_name='test_distributed_run',
                output=['null'],
                observer=[
                    'loads.tests.test_functional.Observer',
                    'loads.tests.test_functional.ObserverFail'
                ],
                users=1,
                hits=5))

        runs = client.list_runs()
        run_id = runs.keys()[0]
        client.stop_run(run_id)

        # checking the metadata
        metadata = client.get_metadata(run_id)
        self.assertEqual(metadata['project_name'], 'test_distributed_run')

        # wait for the run to end
        self._wait_run_over(client)

        # checking the data
        # the run is over so the detailed lines where pruned
        self.assertRaises(ValueError, client.get_data, run_id)
        self.assertEqual(client.get_urls(run_id),
                         {u'http://127.0.0.1:9000/': 10})
        counts = dict(client.get_counts(run_id))
        self.assertEquals(counts['socket_open'], 10)
        self.assertEquals(counts['socket_close'], 10)

        # making sure the observer was called
        with open(_RESULTS) as f:
            data = f.readlines()

        assert len(data) > 0, data
Ejemplo n.º 40
0
    def _test_observer(self):
        runner = Runner(get_runner_args(
            fqn='loads.examples.test_blog.TestWebSite.test_something',
            #output=['null'],
            users=1,
            hits=5,
            agents=1,
            observer=['loads.tests.test_functional.observer',
                      'loads.tests.test_functional.observer_fail']))

        runner.execute()

        # waiting for around 3 s max
        wait = 0
        while not os.path.exists(_RESULTS) and wait < 30:
            time.sleep(.1)
            wait += 1

        with open(_RESULTS) as f:
            data = f.readlines()

        assert len(data) > 2000, data
Ejemplo n.º 41
0
    def test_die(self):
        # make sure a recalcitrant process gets eventually killed
        client = self._get_client()

        start_runner(
            get_runner_args(
                fqn='loads.examples.test_blog.TestWebSite.test_wontdie',
                agents=1,
                project_name='test_distributed_run',
                output=['null'],
                users=1,
                duration=200,
                detach=True))

        run_id, agents = self._wait_run_started(client)

        agent_id = agents[0][0]

        # get the pid of the worker
        status = client.status(agent_id)

        while status['status'] == {}:
            status = client.status(agent_id)
            print status

        worker_pid = int(status['status'].keys()[0])

        # force a stop
        client.stop_run(run_id)

        # we want to make sure the pid is gone in a 6s frame
        start = time.time()
        dead = not self.is_running(worker_pid)
        while not dead and time.time() - start < 6:
            dead = not self.is_running(worker_pid)

        self.assertTrue(dead)
        self._wait_run_over(client)
Ejemplo n.º 42
0
    def test_errors(self):
        client = self._get_client()

        start_runner(get_runner_args(
            fqn='loads.examples.test_blog.TestWebSite.test_will_error',
            agents=1,
            project_name='test_distributed_run',
            output=['null'],
            observer=['loads.tests.test_functional.Observer',
                      'loads.tests.test_functional.ObserverFail'],
            users=1, hits=5))
        run_id, _ = self._wait_run_started(client)
        client.stop_run(run_id)

        # checking the metadata
        metadata = client.get_metadata(run_id)
        self.assertEqual(metadata['project_name'], 'test_distributed_run')

        # checking the data
        # the run is over so the detailed lines where pruned
        # but we have all errors
        errors = list(self.db.get_errors(run_id))
        self.assertTrue(len(errors) > 0)
Ejemplo n.º 43
0
    def test_die(self):
        # make sure a recalcitrant process gets eventually killed
        client = self._get_client()

        start_runner(get_runner_args(
            fqn='loads.examples.test_blog.TestWebSite.test_wontdie',
            agents=1,
            project_name='test_distributed_run',
            output=['null'],
            users=1, duration=200,
            detach=True))

        run_id, agents = self._wait_run_started(client)

        agent_id = agents[0][0]

        # get the pid of the worker
        status = client.status(agent_id)

        while status['status'] == {}:
            status = client.status(agent_id)
            print status

        worker_pid = int(status['status'].keys()[0])

        # force a stop
        client.stop_run(run_id)

        # we want to make sure the pid is gone in a 6s frame
        start = time.time()
        dead = not self.is_running(worker_pid)
        while not dead and time.time() - start < 6:
            dead = not self.is_running(worker_pid)

        self.assertTrue(dead)
        self._wait_run_over(client)
Ejemplo n.º 44
0
 def test_normal_run(self):
     start_runner(get_runner_args(
         fqn='loads.examples.test_blog.TestWebSite.test_something',
         output=['null']))
Ejemplo n.º 45
0
 def test_normal_run_with_users_and_hits(self):
     start_runner(get_runner_args(
         fqn='loads.examples.test_blog.TestWebSite.test_something',
         output=['null'], users=2, hits=2))
Ejemplo n.º 46
0
 def test_normal_run(self):
     start_runner(get_runner_args(
         fqn='loads.examples.test_blog.TestWebSite.test_something',
         output=['null']))