def trigger_task(swarming_url, progress, unique, timeout, index): """Triggers a Swarming job and collects results. Returns the total amount of time to run a task remotely, including all the overhead. """ name = 'load-test-%d-%s' % (index, unique) start = time.time() logging.info('trigger') manifest = swarming.Manifest( None, name, 1, None, swarming_load_test_bot.OS_NAME, '', 'http://localhost:1', False, False, 100, None) data = {'request': manifest.to_json()} response = net.url_open(swarming_url + '/test', data=data) if not response: # Failed to trigger. Return a failure. return 'failed_trigger' result = json.load(response) test_key = result['test_keys'][0].pop('test_key') assert test_key expected = { 'test_case_name': name, 'test_keys': [ { 'config_name': swarming_load_test_bot.OS_NAME, 'num_instances': 1, 'instance_index': 0, }, ], } assert result == expected, result progress.update_item('%5d' % index, processing=1) try: logging.info('collect') test_keys = swarming.get_test_keys(swarming_url, name) if not test_keys: return 'no_test_keys' assert test_keys == [test_key], test_keys out = [ output for _index, output in swarming.yield_results( swarming_url, test_keys, timeout, None) ] if not out: return 'no_result' out[0].pop('machine_tag') out[0].pop('machine_id') expected = [ { u'config_instance_index': 0, u'exit_codes': u'0', u'num_config_instances': 1, u'output': swarming_load_test_bot.TASK_OUTPUT, }, ] assert out == expected, '\n%s\n%s' % (out, expected) return time.time() - start finally: progress.update_item('%5d - done' % index, processing=-1, processed=1)
def get_results(keys, output_collector=None): """Simplifies the call to yield_results(). The timeout is hard-coded to 10 seconds. """ return list( swarming.yield_results( 'https://host:9001', keys, 10., None, True, output_collector))
def get_results(keys, output_collector=None): """Simplifies the call to yield_results(). The timeout is hard-coded to 10 seconds. """ return list( swarming.yield_results( 'https://host:9001', keys, 10., None, True, output_collector, False))
def trigger_task(swarming_url, dimensions, progress, unique, timeout, index): """Triggers a Swarming job and collects results. Returns the total amount of time to run a task remotely, including all the overhead. """ name = 'load-test-%d-%s' % (index, unique) start = time.time() logging.info('trigger') manifest = swarming.Manifest( isolate_server='http://localhost:1', namespace='dummy-isolate', isolated_hash=1, task_name=name, shards=1, env={}, dimensions=dimensions, working_dir=None, deadline=3600, verbose=False, profile=False, priority=100) # TODO(maruel): Make output size configurable. # TODO(maruel): Make number of shards configurable. output_size = 100 cmd = ['python', '-c', 'print(\'1\'*%s)' % output_size] manifest.add_task('echo stuff', cmd) data = {'request': manifest.to_json()} response = net.url_open(swarming_url + '/test', data=data) if not response: # Failed to trigger. Return a failure. return 'failed_trigger' result = json.load(response) test_key = result['test_keys'][0].pop('test_key') assert test_key expected = { 'test_case_name': name, 'test_keys': [ { # Old API uses harcoded config name. 'config_name': 'isolated', 'num_instances': 1, 'instance_index': 0, }, ], } if result != expected: # New API doesn't have concept of config name so it uses the task name. expected['test_keys'][0]['config_name'] = name assert result == expected, '%s\n%s' % (result, expected) progress.update_item('%5d' % index, processing=1) try: logging.info('collect') test_keys = swarming.get_task_keys(swarming_url, name) if not test_keys: return 'no_test_keys' assert test_keys == [test_key], test_keys out = [ output for _index, output in swarming.yield_results( swarming_url, test_keys, timeout, None, False, None) ] if not out: return 'no_result' out[0].pop('machine_tag') out[0].pop('machine_id') expected = [ { u'config_instance_index': 0, u'exit_codes': u'0', u'num_config_instances': 1, u'output': swarming_load_test_bot.TASK_OUTPUT, }, ] assert out == expected, '\n%s\n%s' % (out, expected) return time.time() - start finally: progress.update_item('%5d - done' % index, processing=-1, processed=1)
def trigger_task(swarming_url, dimensions, sleep_time, output_size, progress, unique, timeout, index): """Triggers a Swarming job and collects results. Returns the total amount of time to run a task remotely, including all the overhead. """ name = 'load-test-%d-%s' % (index, unique) start = time.time() logging.info('trigger') manifest = swarming.Manifest(isolate_server='http://localhost:1', namespace='dummy-isolate', isolated_hash=1, task_name=name, extra_args=[], env={}, dimensions=dimensions, deadline=int(timeout - TIMEOUT_OVERHEAD), verbose=False, profile=False, priority=100) cmd = [ 'python', '-c', 'import time; print(\'1\'*%s); time.sleep(%d); print(\'Back\')' % (output_size, sleep_time) ] manifest.add_task('echo stuff', cmd) data = {'request': manifest.to_json()} response = net.url_read(swarming_url + '/test', data=data) if response is None: # Failed to trigger. Return a failure. return 'failed_trigger' result = json.loads(response) # Old API uses harcoded config name. New API doesn't have concept of config # name so it uses the task name. Ignore this detail. test_keys = [] for key in result['test_keys']: key.pop('config_name') test_keys.append(key.pop('test_key')) assert re.match('[0-9a-f]+', test_keys[-1]), test_keys expected = { u'priority': 100, u'test_case_name': unicode(name), u'test_keys': [{ u'num_instances': 1, u'instance_index': 0, }], } assert result == expected, '\n%s\n%s' % (result, expected) progress.update_item('%5d' % index, processing=1) try: logging.info('collect') new_test_keys = swarming.get_task_keys(swarming_url, name) if not new_test_keys: return 'no_test_keys' assert test_keys == new_test_keys, (test_keys, new_test_keys) out = [ output for _index, output in swarming.yield_results( swarming_url, test_keys, timeout, None, False, None, False, True) ] if not out: return 'no_result' for item in out: item.pop('machine_tag') item.pop('machine_id') # TODO(maruel): Assert output even when run on a real bot. _out_actual = item.pop('output') # assert out_actual == swarming_load_test_bot.TASK_OUTPUT, out_actual expected = [{ u'config_instance_index': 0, u'exit_codes': u'0', u'num_config_instances': 1, }] assert out == expected, '\n%s\n%s' % (out, expected) return time.time() - start finally: progress.update_item('%5d - done' % index, processing=-1, processed=1)
def trigger_task(swarming_url, dimensions, sleep_time, output_size, progress, unique, timeout, index): """Triggers a Swarming job and collects results. Returns the total amount of time to run a task remotely, including all the overhead. """ name = "load-test-%d-%s" % (index, unique) start = time.time() logging.info("trigger") manifest = swarming.Manifest( isolate_server="http://localhost:1", namespace="dummy-isolate", isolated_hash=1, task_name=name, extra_args=[], env={}, dimensions=dimensions, deadline=int(timeout - TIMEOUT_OVERHEAD), verbose=False, profile=False, priority=100, ) cmd = ["python", "-c", "import time; print('1'*%s); time.sleep(%d); print('Back')" % (output_size, sleep_time)] manifest.add_task("echo stuff", cmd) data = {"request": manifest.to_json()} response = net.url_open(swarming_url + "/test", data=data) if not response: # Failed to trigger. Return a failure. return "failed_trigger" result = json.load(response) # Old API uses harcoded config name. New API doesn't have concept of config # name so it uses the task name. Ignore this detail. test_keys = [] for key in result["test_keys"]: key.pop("config_name") test_keys.append(key.pop("test_key")) assert re.match("[0-9a-f]+", test_keys[-1]), test_keys expected = { u"priority": 100, u"test_case_name": unicode(name), u"test_keys": [{u"num_instances": 1, u"instance_index": 0}], } assert result == expected, "\n%s\n%s" % (result, expected) progress.update_item("%5d" % index, processing=1) try: logging.info("collect") new_test_keys = swarming.get_task_keys(swarming_url, name) if not new_test_keys: return "no_test_keys" assert test_keys == new_test_keys, (test_keys, new_test_keys) out = [output for _index, output in swarming.yield_results(swarming_url, test_keys, timeout, None, False, None)] if not out: return "no_result" for item in out: item.pop("machine_tag") item.pop("machine_id") # TODO(maruel): Assert output even when run on a real bot. _out_actual = item.pop("output") # assert out_actual == swarming_load_test_bot.TASK_OUTPUT, out_actual expected = [{u"config_instance_index": 0, u"exit_codes": u"0", u"num_config_instances": 1}] assert out == expected, "\n%s\n%s" % (out, expected) return time.time() - start finally: progress.update_item("%5d - done" % index, processing=-1, processed=1)
def get_swarm_results(keys): """Simplifies the call to yield_results(). The timeout is hard-coded to 10 seconds. """ return list(swarming.yield_results('http://host:9001', keys, 10., None))
def trigger_task( swarming_url, dimensions, sleep_time, output_size, progress, unique, timeout, index): """Triggers a Swarming job and collects results. Returns the total amount of time to run a task remotely, including all the overhead. """ name = 'load-test-%d-%s' % (index, unique) start = time.time() logging.info('trigger') manifest = swarming.Manifest( isolate_server='http://localhost:1', namespace='dummy-isolate', isolated_hash=1, task_name=name, extra_args=[], env={}, dimensions=dimensions, working_dir=None, deadline=3600, verbose=False, profile=False, priority=100) cmd = [ 'python', '-c', 'import time; print(\'1\'*%s); time.sleep(%d); print(\'Back\')' % (output_size, sleep_time) ] manifest.add_task('echo stuff', cmd) data = {'request': manifest.to_json()} response = net.url_open(swarming_url + '/test', data=data) if not response: # Failed to trigger. Return a failure. return 'failed_trigger' result = json.load(response) # Old API uses harcoded config name. New API doesn't have concept of config # name so it uses the task name. Ignore this detail. test_keys = [] for key in result['test_keys']: key.pop('config_name') test_keys.append(key.pop('test_key')) assert re.match('[0-9a-f]+', test_keys[-1]), test_keys expected = { u'test_case_name': unicode(name), u'test_keys': [ { u'num_instances': 1, u'instance_index': 0, } ], } assert result == expected, '\n%s\n%s' % (result, expected) progress.update_item('%5d' % index, processing=1) try: logging.info('collect') new_test_keys = swarming.get_task_keys(swarming_url, name) if not new_test_keys: return 'no_test_keys' assert test_keys == new_test_keys, (test_keys, new_test_keys) out = [ output for _index, output in swarming.yield_results( swarming_url, test_keys, timeout, None, False, None) ] if not out: return 'no_result' for item in out: item.pop('machine_tag') item.pop('machine_id') # TODO(maruel): Assert output even when run on a real bot. _out_actual = item.pop('output') # assert out_actual == swarming_load_test_bot.TASK_OUTPUT, out_actual expected = [ { u'config_instance_index': 0, u'exit_codes': u'0', u'num_config_instances': 1, } ] assert out == expected, '\n%s\n%s' % (out, expected) return time.time() - start finally: progress.update_item('%5d - done' % index, processing=-1, processed=1)
def trigger_task(swarming_url, dimensions, progress, unique, timeout, index): """Triggers a Swarming job and collects results. Returns the total amount of time to run a task remotely, including all the overhead. """ name = 'load-test-%d-%s' % (index, unique) start = time.time() logging.info('trigger') manifest = swarming.Manifest(isolate_server='http://localhost:1', namespace='dummy-isolate', isolated_hash=1, task_name=name, shards=1, env={}, dimensions=dimensions, working_dir=None, deadline=3600, verbose=False, profile=False, priority=100) # TODO(maruel): Make output size configurable. # TODO(maruel): Make number of shards configurable. output_size = 100 cmd = ['python', '-c', 'print(\'1\'*%s)' % output_size] manifest.add_task('echo stuff', cmd) data = {'request': manifest.to_json()} response = net.url_open(swarming_url + '/test', data=data) if not response: # Failed to trigger. Return a failure. return 'failed_trigger' result = json.load(response) test_key = result['test_keys'][0].pop('test_key') assert test_key expected = { 'test_case_name': name, 'test_keys': [ { # Old API uses harcoded config name. 'config_name': 'isolated', 'num_instances': 1, 'instance_index': 0, }, ], } if result != expected: # New API doesn't have concept of config name so it uses the task name. expected['test_keys'][0]['config_name'] = name assert result == expected, '%s\n%s' % (result, expected) progress.update_item('%5d' % index, processing=1) try: logging.info('collect') test_keys = swarming.get_task_keys(swarming_url, name) if not test_keys: return 'no_test_keys' assert test_keys == [test_key], test_keys out = [ output for _index, output in swarming.yield_results( swarming_url, test_keys, timeout, None, False, None) ] if not out: return 'no_result' out[0].pop('machine_tag') out[0].pop('machine_id') expected = [ { u'config_instance_index': 0, u'exit_codes': u'0', u'num_config_instances': 1, u'output': swarming_load_test_bot.TASK_OUTPUT, }, ] assert out == expected, '\n%s\n%s' % (out, expected) return time.time() - start finally: progress.update_item('%5d - done' % index, processing=-1, processed=1)