diff --git a/integration_test/helper.sh b/integration_test/helper.sh index 22f41a5e..4d540037 100644 --- a/integration_test/helper.sh +++ b/integration_test/helper.sh @@ -16,43 +16,36 @@ function compile_file() { erlc -o "$output_dir" "$erl_file" } -function contains() { - local pipeline='cat -' +function contains_all() { + local output="$(cat -)" + local ret= acc=0 for pattern in "$@"; do - pipeline+=" | tee >(grep -q -e \"$pattern\"; echo \"+\$?\")" + ret="$(echo "$output" | grep -L -e "$pattern" | wc -l)" + if [ "$ret" -ne "0" ]; then + [ "$(($acc))" -eq "0" ] && { + echo "contains_all FAILED" + echo "stdin: '${output}'"; } + echo "pattern is missing: '${pattern}'" + fi >&2 + acc+="+${ret}" done - pipeline+=' >/dev/null' - local output="$(eval "$pipeline")" - test "$(($output))" -eq 0 + test "$(($acc))" -eq 0 } -function doesnt_contain() { - local pipeline='cat -' +function doesnt_contain_any() { + local output="$(cat -)" + local ret= acc=0 for pattern in "$@"; do - pipeline+=" | tee >(grep -q -v -e \"$pattern\"; echo \"+\$?\")" + ret="$(echo "$output" | grep -l -e "$pattern" | wc -l || true)" + if [ "$ret" -ne "0" ]; then + [ "$(($acc))" -eq "0" ] && { + echo "doesnt_contain_any FAILED" + echo "stdin: '${output}'"; } + echo "pattern is present: '${pattern}'" + fi >&2 + acc+="+${ret}" done - pipeline+=' >/dev/null' - local output="$(eval "$pipeline")" - test "$(($output))" -eq 0 -} - -function wait_for_cmd() { - local timeout="${1:-0}" - local cmd="${2:-true}" - shift 2 - local full_cmd=("$cmd" "$@") - echo "Waiting for '${full_cmd[@]}'" - for i in $(seq 0 "${timeout}"); do - if "${full_cmd[@]}"; then - [ "$i" -ne 0 ] && echo - echo "Waiting is done after $i seconds" - return 0 - fi - echo -n "." - sleep 1 - done - echo -e "\nKilled by timeout" - return 1 + test "$(($acc))" -eq 0 } ###################### @@ -70,15 +63,6 @@ function amoc_eval() { docker_compose exec -T "$service" "$exec_path" eval "$@" } -function container_is_healthy() { - docker_compose ps $1 | contains "healthy" -} - -function wait_for_healthcheck() { - local container=$1 - wait_for_cmd 60 container_is_healthy "$container" -} - ###################### ## common variables ## ###################### diff --git a/integration_test/start_test_cluster.sh b/integration_test/start_test_cluster.sh index 344ad9b4..c5b78d11 100755 --- a/integration_test/start_test_cluster.sh +++ b/integration_test/start_test_cluster.sh @@ -6,8 +6,4 @@ enable_strict_mode compile_file integration_test/extra_code_paths/path1/dummy_helper.erl compile_file integration_test/extra_code_paths/path2/dummy_scenario.erl -docker_compose up -d amoc-{master,worker-1,worker-2} - -wait_for_healthcheck amoc-master -wait_for_healthcheck amoc-worker-1 -wait_for_healthcheck amoc-worker-2 +docker_compose up --wait --wait-timeout 100 amoc-{master,worker-1,worker-2} diff --git a/integration_test/test_add_new_node.sh b/integration_test/test_add_new_node.sh index 3cde287c..fa38b99c 100755 --- a/integration_test/test_add_new_node.sh +++ b/integration_test/test_add_new_node.sh @@ -3,10 +3,9 @@ source "$(dirname "$0")/helper.sh" enable_strict_mode -docker_compose up -d amoc-worker-3 -wait_for_healthcheck amoc-worker-3 +docker_compose up --wait --wait-timeout 100 amoc-worker-3 -amoc_eval amoc-worker-3 "amoc_controller:get_status()." | contains dummy_scenario running -amoc_eval amoc-worker-3 "binary_to_list(amoc_config:get(test))." | contains "test_value" -amoc_eval amoc-worker-3 "dummy_helper:test_amoc_dist()." | contains 'amoc_dist_works_as_expected' +amoc_eval amoc-worker-3 "amoc_controller:get_status()." | contains_all dummy_scenario running +amoc_eval amoc-worker-3 "binary_to_list(amoc_config:get(test))." | contains_all "test_value" +amoc_eval amoc-worker-3 "dummy_helper:test_amoc_dist()." | contains_all 'amoc_dist_works_as_expected' echo "amoc_dist_works_as_expected" diff --git a/integration_test/test_amoc_cluster.sh b/integration_test/test_amoc_cluster.sh index 99bc5da7..7666de6a 100755 --- a/integration_test/test_amoc_cluster.sh +++ b/integration_test/test_amoc_cluster.sh @@ -4,14 +4,14 @@ source "$(dirname "$0")/helper.sh" enable_strict_mode echo "checking that clustering is done properly" -amoc_eval amoc-master "nodes()." | contains amoc-worker-1 amoc-worker-2 -amoc_eval amoc-worker-1 "nodes()." | contains amoc-master amoc-worker-2 -amoc_eval amoc-worker-2 "nodes()." | contains amoc-master amoc-worker-1 +amoc_eval amoc-master "nodes()." | contains_all amoc-worker-1 amoc-worker-2 +amoc_eval amoc-worker-1 "nodes()." | contains_all amoc-master amoc-worker-2 +amoc_eval amoc-worker-2 "nodes()." | contains_all amoc-master amoc-worker-1 -echo "checking that AMOC_EXTRA_CODE_PATHS setting works as expected" -amoc_eval amoc-master "amoc_code_server:list_scenario_modules()." | contains dummy_scenario -amoc_eval amoc-master "amoc_code_server:list_configurable_modules()." | contains dummy_helper -amoc_eval amoc-worker-1 "amoc_code_server:list_scenario_modules()." | doesnt_contain dummy_scenario -amoc_eval amoc-worker-1 "amoc_code_server:list_configurable_modules()." | doesnt_contain dummy_helper -amoc_eval amoc-worker-2 "amoc_code_server:list_scenario_modules()." | doesnt_contain dummy_scenario -amoc_eval amoc-worker-2 "amoc_code_server:list_configurable_modules()." | doesnt_contain dummy_helper +echo "checking that setting AMOC_EXTRA_CODE_PATHS env works as expected" +amoc_eval amoc-master "amoc_code_server:list_scenario_modules()." | contains_all dummy_scenario +amoc_eval amoc-master "amoc_code_server:list_configurable_modules()." | contains_all dummy_helper +amoc_eval amoc-worker-1 "amoc_code_server:list_scenario_modules()." | doesnt_contain_any dummy_scenario +amoc_eval amoc-worker-1 "amoc_code_server:list_configurable_modules()." | doesnt_contain_any dummy_helper +amoc_eval amoc-worker-2 "amoc_code_server:list_scenario_modules()." | doesnt_contain_any dummy_scenario +amoc_eval amoc-worker-2 "amoc_code_server:list_configurable_modules()." | doesnt_contain_any dummy_helper diff --git a/integration_test/test_distribute_scenario.sh b/integration_test/test_distribute_scenario.sh index 57ebcf1f..9264ccc1 100755 --- a/integration_test/test_distribute_scenario.sh +++ b/integration_test/test_distribute_scenario.sh @@ -56,21 +56,21 @@ function distribute_modules() { amoc_eval "${1}" "amoc_code_server:distribute_modules('amoc@${2}')." } -ensure_modules_loaded amoc-master "${modules[@]}" | contains "${modules[@]}" -ensure_modules_loaded amoc-worker-1 "${modules[@]}" | doesnt_contain "${modules[@]}" -ensure_modules_loaded amoc-worker-2 "${modules[@]}" | doesnt_contain "${modules[@]}" +ensure_modules_loaded amoc-master "${modules[@]}" | contains_all "${modules[@]}" +ensure_modules_loaded amoc-worker-1 "${modules[@]}" | doesnt_contain_any "${modules[@]}" +ensure_modules_loaded amoc-worker-2 "${modules[@]}" | doesnt_contain_any "${modules[@]}" -list_scenarios_and_helpers amoc-worker-2 | doesnt_contain "${modules[@]}" -list_scenarios_and_helpers amoc-worker-1 | doesnt_contain "${modules[@]}" +list_scenarios_and_helpers amoc-worker-2 | doesnt_contain_any "${modules[@]}" +list_scenarios_and_helpers amoc-worker-1 | doesnt_contain_any "${modules[@]}" echo "Distributing scenario and helper module from the amoc-master node" ## amoc_controller is added to the list as an example of module ## that already exists on all the slave amoc nodes add_module amoc-master "${modules[@]}" amoc_controller -distribute_modules amoc-master amoc-worker-1 | contains "${modules[@]}" amoc_controller +distribute_modules amoc-master amoc-worker-1 | contains_all "${modules[@]}" amoc_controller -ensure_modules_loaded amoc-worker-1 "${modules[@]}" | contains "${modules[@]}" -ensure_modules_loaded amoc-worker-2 "${modules[@]}" | doesnt_contain "${modules[@]}" +ensure_modules_loaded amoc-worker-1 "${modules[@]}" | contains_all "${modules[@]}" +ensure_modules_loaded amoc-worker-2 "${modules[@]}" | doesnt_contain_any "${modules[@]}" -list_scenarios_and_helpers amoc-worker-1 | contains "${modules[@]}" -list_scenarios_and_helpers amoc-worker-2 | doesnt_contain "${modules[@]}" +list_scenarios_and_helpers amoc-worker-1 | contains_all "${modules[@]}" +list_scenarios_and_helpers amoc-worker-2 | doesnt_contain_any "${modules[@]}" diff --git a/integration_test/test_run_scenario.sh b/integration_test/test_run_scenario.sh index c5735dbb..bd2caf90 100755 --- a/integration_test/test_run_scenario.sh +++ b/integration_test/test_run_scenario.sh @@ -14,7 +14,7 @@ result="$(run_scenario amoc-master dummy_scenario 10)" echo "$result" -if echo "$result" | contains "ok" "'amoc@amoc-worker-1'" "'amoc@amoc-worker-2'" ; then +if echo "$result" | contains_all "ok" "'amoc@amoc-worker-1'" "'amoc@amoc-worker-2'" ; then echo "Scenario executed" exit 0 else diff --git a/src/amoc_config/amoc_config_parser.erl b/src/amoc_config/amoc_config_parser.erl index 52a61815..f91a2bbb 100644 --- a/src/amoc_config/amoc_config_parser.erl +++ b/src/amoc_config/amoc_config_parser.erl @@ -9,13 +9,9 @@ -export([parse_value/1]). --ifdef(TEST). -%% exported for testing only +%% format/2 is exported for testing purposes +%% it is also re-used by amoc-arsenal -export([format/2]). --else. --ignore_xref([format/2]). --dialyzer({nowarn_function, [format/2]}). --endif. %% ------------------------------------------------------------------ %% API