Skip to content

Commit

Permalink
Merge pull request #154 from esl/amoc-arsenal
Browse files Browse the repository at this point in the history
Amoc arsenal

this PR introduces the following changes:
    exporting format/2 functin, since it's required for the REST API in amoc-arsenal
    fixing some functions in integration tests
  • Loading branch information
NelsonVides authored Nov 24, 2023
2 parents 5daada2 + 131f596 commit dc2a825
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 77 deletions.
64 changes: 24 additions & 40 deletions integration_test/helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

######################
Expand All @@ -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 ##
######################
Expand Down
6 changes: 1 addition & 5 deletions integration_test/start_test_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
9 changes: 4 additions & 5 deletions integration_test/test_add_new_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
20 changes: 10 additions & 10 deletions integration_test/test_amoc_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 10 additions & 10 deletions integration_test/test_distribute_scenario.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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[@]}"
2 changes: 1 addition & 1 deletion integration_test/test_run_scenario.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions src/amoc_config/amoc_config_parser.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dc2a825

Please sign in to comment.