<s> import os <EOL> import tempfile <EOL> from unittest import skip <EOL> import yaml <EOL> from genty import genty , genty_dataset <EOL> from app . master . build_artifact import BuildArtifact <EOL> from test . framework . functional . base_functional_test_case import BaseFunctionalTestCase <EOL> from test . framework . functional . fs_item import Directory , File <EOL> from test . functional . job_configs import BASIC_FAILING_JOB , BASIC_JOB , JOB_WITH_SETUP_AND_TEARDOWN <EOL> @ genty <EOL> class TestClusterBasic ( BaseFunctionalTestCase ) : <EOL> @ genty_dataset ( <EOL> basic_job = ( BASIC_JOB , '<STR_LIT>' ) , <EOL> basic_failing_job = ( BASIC_FAILING_JOB , '<STR_LIT>' ) , <EOL> job_with_setup_and_teardown = ( JOB_WITH_SETUP_AND_TEARDOWN , '<STR_LIT>' ) , <EOL> ) <EOL> def test_basic_directory_configs_end_to_end ( self , test_job_config , job_name ) : <EOL> master = self . cluster . start_master ( ) <EOL> slave = self . cluster . start_slave ( ) <EOL> project_dir = tempfile . TemporaryDirectory ( ) <EOL> build_resp = master . post_new_build ( { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : yaml . safe_load ( test_job_config . config [ os . name ] ) [ job_name ] , <EOL> '<STR_LIT>' : project_dir . name , <EOL> } ) <EOL> build_id = build_resp [ '<STR_LIT>' ] <EOL> master . block_until_build_finished ( build_id , timeout = <NUM_LIT:30> ) <EOL> slave . block_until_idle ( timeout = <NUM_LIT:20> ) <EOL> self . _assert_build_completed_as_expected ( build_id , test_job_config , project_dir ) <EOL> @ skip ( '<STR_LIT>' ) <EOL> def test_git_type_demo_project_config ( self ) : <EOL> master = self . cluster . start_master ( ) <EOL> self . cluster . start_slave ( num_executors_per_slave = <NUM_LIT:10> ) <EOL> build_resp = master . post_new_build ( { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> build_id = build_resp [ '<STR_LIT>' ] <EOL> master . block_until_build_finished ( build_id , timeout = <NUM_LIT:20> ) <EOL> expected_artifact_contents = [ <EOL> Directory ( '<STR_LIT>' . format ( i ) , [ <EOL> File ( '<STR_LIT>' ) , <EOL> File ( '<STR_LIT>' , contents = '<STR_LIT>' . format ( i + <NUM_LIT:1> ) ) , <EOL> File ( '<STR_LIT>' , contents = '<STR_LIT>' ) , <EOL> File ( '<STR_LIT>' ) , <EOL> ] ) <EOL> for i in range ( <NUM_LIT:10> ) <EOL> ] <EOL> expected_artifact_contents . append ( File ( BuildArtifact . ARTIFACT_FILE_NAME ) ) <EOL> self . assert_build_has_successful_status ( build_id = build_id ) <EOL> self . assert_build_status_contains_expected_data ( <EOL> build_id = build_id , expected_data = { '<STR_LIT>' : <NUM_LIT:10> , '<STR_LIT>' : <NUM_LIT:10> } ) <EOL> self . assert_build_artifact_contents_match_expected ( <EOL> build_id = build_id , expected_build_artifact_contents = expected_artifact_contents ) <EOL> def test_slave_reconnection_does_not_take_down_master ( self ) : <EOL> test_config = JOB_WITH_SETUP_AND_TEARDOWN <EOL> job_config = yaml . safe_load ( test_config . config [ os . name ] ) [ '<STR_LIT>' ] <EOL> master = self . cluster . start_master ( ) <EOL> self . cluster . start_slave ( num_executors_per_slave = <NUM_LIT:5> , start_port = <NUM_LIT> ) <EOL> self . cluster . kill_slaves ( kill_gracefully = False ) <EOL> slave = self . cluster . start_slave ( num_executors_per_slave = <NUM_LIT:5> , start_port = <NUM_LIT> ) <EOL> project_dir = tempfile . TemporaryDirectory ( ) <EOL> build_1 = master . post_new_build ( { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : job_config , <EOL> '<STR_LIT>' : project_dir . name , <EOL> } ) <EOL> build_2 = master . post_new_build ( { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : job_config , <EOL> '<STR_LIT>' : project_dir . name , <EOL> } ) <EOL> master . block_until_build_finished ( build_1 [ '<STR_LIT>' ] , timeout = <NUM_LIT:30> ) <EOL> master . block_until_build_finished ( build_2 [ '<STR_LIT>' ] , timeout = <NUM_LIT:30> ) <EOL> slave . block_until_idle ( timeout = <NUM_LIT:20> ) <EOL> self . _assert_build_completed_as_expected ( build_1 [ '<STR_LIT>' ] , test_config , project_dir ) <EOL> self . _assert_build_completed_as_expected ( build_2 [ '<STR_LIT>' ] , test_config , project_dir ) <EOL> def _assert_build_completed_as_expected ( self , build_id , test_job_config , project_dir ) : <EOL> if test_job_config . expected_to_fail : <EOL> self . assert_build_has_failure_status ( build_id = build_id ) <EOL> else : <EOL> self . assert_build_has_successful_status ( build_id = build_id ) <EOL> self . assert_build_status_contains_expected_data ( <EOL> build_id = build_id , <EOL> expected_data = { <EOL> '<STR_LIT>' : test_job_config . expected_num_atoms , <EOL> '<STR_LIT>' : test_job_config . expected_num_atoms } ) <EOL> self . assert_build_artifact_contents_match_expected ( <EOL> master_api = self . cluster . master_api_client . _api , <EOL> build_id = build_id , <EOL> expected_build_artifact_contents = test_job_config . expected_artifact_contents <EOL> ) <EOL> self . assert_directory_contents_match_expected ( <EOL> dir_path = project_dir . name , expected_dir_contents = test_job_config . expected_project_dir_contents ) </s>
