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
def start_servers(): procs = [] procs.append(start_process('loads.transport.broker')) for x in range(3): procs.append(start_process('loads.transport.agent')) procs.append(start_process('loads.examples.echo_server')) # wait for the echo server to be started tries = 0 while True: try: requests.get('http://0.0.0.0:9000') break except requests.ConnectionError: time.sleep(.2) tries += 1 if tries > 20: raise # wait for the broker to be up with 3 slaves. client = Pool() while len(client.list()) != 3: time.sleep(.1) # control that the broker is responsive client.ping() for wid in client.list(): status = client.status(wid)['status'] assert status == {}, status client.close() return procs
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))
def start_servers(): if len(_PROCS) != 0: return _PROCS _PROCS.append( start_process('loads.transport.broker', '--db', 'python', '--heartbeat', 'tcp://0.0.0.0:9876')) for x in range(10): _PROCS.append(start_process('loads.transport.agent')) _PROCS.append(start_process('loads.examples.echo_server')) # wait for the echo server to be started tries = 0 while True: try: requests.get('http://0.0.0.0:9000') break except requests.ConnectionError: time.sleep(.2) tries += 1 if tries > 20: raise # wait for the broker to be up with 3 slaves. client = Pool() while len(client.list()) != 10: time.sleep(.1) # control that the broker is responsive client.ping() for wid in client.list(): status = client.status(wid)['status'] assert status == {}, status client.close() if verify_broker() is None: raise ValueError('Broker seem down') return _PROCS
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')
def _get_client(self): client = Pool() while len(client.list_runs()) > 0: time.sleep(.2) return client