Esempio n. 1
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))
Esempio n. 2
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
Esempio n. 3
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')
Esempio 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
Esempio n. 5
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)
Esempio n. 6
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
Esempio n. 7
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')
Esempio n. 8
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')
Esempio 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')
Esempio 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
Esempio n. 11
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'])
Esempio n. 12
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'])
Esempio n. 13
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)
Esempio n. 14
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))
Esempio n. 15
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))
Esempio n. 16
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)
Esempio n. 17
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))
Esempio n. 18
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')
Esempio n. 19
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")
Esempio n. 20
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')
Esempio n. 21
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))
Esempio n. 22
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))
Esempio n. 23
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))
Esempio n. 24
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')
Esempio n. 25
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')
Esempio n. 26
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
Esempio n. 27
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)
Esempio n. 28
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)
Esempio n. 29
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)
Esempio n. 30
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))
Esempio n. 31
0
 def test_normal_run(self):
     start_runner(get_runner_args(
         fqn='loads.examples.test_blog.TestWebSite.test_something',
         output=['null']))
Esempio n. 32
0
 def test_normal_run(self):
     start_runner(get_runner_args(
         fqn='loads.examples.test_blog.TestWebSite.test_something',
         output=['null']))