def test_json_strip_prefix(): with mock_api.api(__file__) as api: flow_name = api.flow_job() api.job('j1', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=1) api.job('j2', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=2) api.job('j3', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3) api.job('j4', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3) api.job('j5', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3) api.job('j6', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3) api.job('j7_unchecked', exec_time=40, max_fails=0, expect_invocations=1, invocation_delay=0.0000000000001, expect_order=None, unknown_result=True) api.job('j8_unchecked', exec_time=40, max_fails=0, expect_invocations=1, invocation_delay=0.0000000000001, expect_order=None, unknown_result=True) api.job('j9', exec_time=5, max_fails=0, expect_invocations=1, expect_order=4) ctrl1 = _flow(api, True, flow_graph_dir(flow_name)) # Test pretty printing json_file = jp(flow_graph_dir(flow_name), "pretty.json") ctrl1.json(json_file, indent=4) with open(json_file) as jf: _assert_json(jf.read().strip(), _pretty_json) # Test default compact json with open(ctrl1.json_file) as jf: _assert_json(jf.read().strip(), _compact_json) # Test return json json = ctrl1.json(None) _assert_json(json, _compact_json)
def test_json_unchecked_only_in_flows(): with mock_api.api(__file__) as api: flow_name = api.flow_job() api.job('j1_unchecked', exec_time=40, max_fails=0, expect_invocations=1, invocation_delay=0.0000000000001, expect_order=None, unknown_result=True) api.job('j2_unchecked', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=None) api.job('j3_unchecked', exec_time=40, max_fails=0, expect_invocations=1, invocation_delay=0.0000000000001, expect_order=None, unknown_result=True) api.job('j4_unchecked', exec_time=40, max_fails=0, expect_invocations=1, invocation_delay=0.0000000000001, expect_order=None, unknown_result=True) api.job('j5_unchecked', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=None) api.job('j6', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=1) api.job('j7', exec_time=5, max_fails=0, expect_invocations=1, expect_order=2) json_dir = flow_graph_dir(flow_name) if not os.path.exists(json_dir): os.makedirs(json_dir) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1, json_dir=json_dir) as ctrl1: ctrl1.invoke_unchecked('j1_unchecked') with ctrl1.parallel(timeout=40, report_interval=3) as ctrl2: with ctrl2.serial(timeout=40, report_interval=3) as ctrl3a: ctrl3a.invoke_unchecked('j2_unchecked') ctrl3a.invoke_unchecked('j3_unchecked') with ctrl2.parallel(timeout=40, report_interval=3) as ctrl3b: ctrl3b.invoke_unchecked('j4_unchecked') ctrl3b.invoke_unchecked('j5_unchecked') ctrl1.invoke('j6') ctrl1.invoke('j7') # Test default compact json with open(ctrl1.json_file) as got_jf, open(jp(here, "json_test_unchecked_compact.json")) as expected_jf: _assert_json(got_jf.read().strip(), expected_jf.read().strip())
def test_propagate_unstable_parallel_single_unstable(env_base_url, fake_java, capfd): with mock_api.api(__file__) as api: api.flow_job() api.job('j11_unstable', 0.01, max_fails=0, expect_invocations=1, expect_order=1, final_result='unstable') with parallel(api, timeout=70, username=username, password=password, job_name_prefix=api.job_name_prefix) as ctrl1: ctrl1.invoke('j11_unstable') assert ctrl1.result == BuildResult.UNSTABLE
def test_just_dump_no_json(): with mock_api.api(__file__) as api: api.flow_job() api.job('j1', exec_time=0.01, max_fails=0, expect_invocations=0, expect_order=None) api.job('j2', exec_time=0.01, max_fails=0, expect_invocations=0, expect_order=None) api.job('j3_unchecked', exec_time=40, max_fails=0, expect_invocations=0, expect_order=None) api.job('j4', exec_time=5, max_fails=0, expect_invocations=0, expect_order=None) api.job('j5', exec_time=5, max_fails=0, expect_invocations=0, expect_order=None) _flow(api, None)
def test_propagate_unstable_serial_toplevel(env_base_url, fake_java, capfd): with mock_api.api(__file__) as api: api.flow_job() api.job('j11', 0.01, max_fails=0, expect_invocations=1, expect_order=1) api.job('j12_unstable', 0.01, max_fails=0, expect_invocations=1, expect_order=2, final_result='unstable', serial=True) api.job('j13', 0.01, max_fails=0, expect_invocations=1, expect_order=3, serial=True) with serial(api, timeout=70, username=username, password=password, job_name_prefix=api.job_name_prefix) as ctrl1: ctrl1.invoke('j11') ctrl1.invoke('j12_unstable') ctrl1.invoke('j13') assert ctrl1.result == BuildResult.UNSTABLE
def test_propagate_unstable_parallel_inner_fail_before(env_base_url, fake_java, capfd): with mock_api.api(__file__) as api: api.flow_job() api.job('j11', 0.01, max_fails=0, expect_invocations=1, expect_order=1) api.job('j21_fail', 0.01, max_fails=1, expect_invocations=1, expect_order=2, serial=True) api.job('j22_unstable', 0.01, max_fails=0, expect_invocations=1, expect_order=2, final_result='unstable') api.job('j23', 0.01, max_fails=0, expect_invocations=1, expect_order=2) with raises(FailedChildJobException): with serial(api, timeout=70, username=username, password=password, job_name_prefix=api.job_name_prefix) as ctrl1: ctrl1.invoke('j11') with ctrl1.parallel() as ctrl2: ctrl2.invoke('j21_fail') ctrl2.invoke('j22_unstable') ctrl2.invoke('j23')
def test_just_dump_with_json(): with mock_api.api(__file__) as api: flow_name = api.flow_job() api.job('j1', exec_time=0.01, max_fails=0, expect_invocations=0, expect_order=None) api.job('j2', exec_time=0.01, max_fails=0, expect_invocations=0, expect_order=None) api.job('j3_unchecked', exec_time=40, max_fails=0, expect_invocations=0, expect_order=None) api.job('j4', exec_time=5, max_fails=0, expect_invocations=0, expect_order=None) api.job('j5', exec_time=5, max_fails=0, expect_invocations=0, expect_order=None) fgd = flow_graph_dir(flow_name) ctrl1 = _flow(api, fgd) # Test json json = ctrl1.json(None) _assert_json(json, _compact_json)
def test_json_no_strip_prefix(): with mock_api.api(__file__) as api: flow_name = api.flow_job() api.job('j1', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=1) api.job('j2', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=2) api.job('j3', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3) api.job('j4', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3) api.job('j5', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3) api.job('j6', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3) api.job('j7_unchecked', exec_time=40, max_fails=0, expect_invocations=1, invocation_delay=0.0000000000001, expect_order=None, unknown_result=True) api.job('j8_unchecked', exec_time=40, max_fails=0, expect_invocations=1, invocation_delay=0.0000000000001, expect_order=None, unknown_result=True) api.job('j9', exec_time=5, max_fails=0, expect_invocations=1, expect_order=4) ctrl1 = _flow(api, False, flow_graph_dir(flow_name)) # Test pretty printing with no stripping of top level prefix json_file = jp(flow_graph_dir(flow_name), "verbose_pretty.json") ctrl1.json(json_file, indent=4) with open(json_file) as jf: got_json = jf.read().strip() expect_json = _pretty_json.replace('strip_prefix', 'no_strip_prefix').replace('name": "', 'name": "jenkinsflow_test__json_no_strip_prefix__') _assert_json(got_json, expect_json)