Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle multi worker #113

Merged
merged 5 commits into from Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/common.sh
Expand Up @@ -14,10 +14,11 @@ DIST=${DIST:-buster}
# Yunohost version: stable, testing or unstable
YNH_BRANCH=${YNH_BRANCH:-stable}

WORKER_ID=${WORKER_ID:-0}
LXC_BASE="ynh-appci-$DIST-$ARCH-$YNH_BRANCH-base"
LXC_NAME="ynh-appci-$DIST-$ARCH-$YNH_BRANCH-test"
LXC_NAME="ynh-appci-$DIST-$ARCH-$YNH_BRANCH-test-${WORKER_ID}"

readonly lock_file="./pcheck.lock"
readonly lock_file="./pcheck-${WORKER_ID}.lock"

DEFAULT_PHP_VERSION="7.3"
[[ "$DIST" == "bullseye" ]] && DEFAULT_PHP_VERSION="7.4"
Expand Down
7 changes: 6 additions & 1 deletion lib/lxc.sh
Expand Up @@ -25,7 +25,12 @@ LXC_CREATE () {
else
log_critical "Can't find base image $LXC_BASE, run ./package_check.sh --rebuild"
fi
[[ "${PIPESTATUS[0]}" -eq 0 ]] || exit 1

pipestatus="${PIPESTATUS[0]}"
location=$(lxc list --format json | jq -e --arg LXC_NAME $LXC_NAME '.[] | select(.name==$LXC_NAME) | .location' | tr -d '"')
[[ "$location" != "none" ]] && log_info "... on $location"

[[ "$pipestatus" -eq 0 ]] || exit 1

_LXC_START_AND_WAIT $LXC_NAME
set_witness_files
Expand Down
18 changes: 10 additions & 8 deletions lib/tests.sh
Expand Up @@ -187,16 +187,18 @@ _VALIDATE_THAT_APP_CAN_BE_ACCESSED () {
log_debug "Running curl $check_domain$curl_check_path"

# Call cURL to try to access to the URL of the app
curl --location --insecure --silent --show-error \
--header "Host: $check_domain" \
LXC_EXEC "curl --location --insecure --silent --show-error \
--header 'Host: $check_domain' \
--resolve $DOMAIN:80:$LXC_IP \
--resolve $DOMAIN:443:$LXC_IP \
--resolve $SUBDOMAIN:80:$LXC_IP \
--resolve $SUBDOMAIN:443:$LXC_IP \
--write-out "%{http_code};%{url_effective}\n" \
--output "$curl_output" \
$check_domain$curl_check_path \
> "./curl_print"
--write-out '%{http_code};%{url_effective}\n' \
--output './curl_output' \
$check_domain$curl_check_path" \
> "$TEST_CONTEXT/curl_print"

LXC_EXEC "cat ./curl_output" > $curl_output

# Analyze the result of curl command
if [ $? -ne 0 ]
Expand All @@ -205,7 +207,7 @@ _VALIDATE_THAT_APP_CAN_BE_ACCESSED () {
curl_error=1
fi

http_code=$(cat "./curl_print" | cut -d ';' -f1)
http_code=$(cat "$TEST_CONTEXT/curl_print" | cut -d ';' -f1)

log_debug "HTTP code: $http_code"

Expand Down Expand Up @@ -245,7 +247,7 @@ _VALIDATE_THAT_APP_CAN_BE_ACCESSED () {
fi

echo -e "Test URL: $check_domain$curl_check_path
Real URL: $(cat "./curl_print" | cut --delimiter=';' --fields=2)
Real URL: $(cat "$TEST_CONTEXT/curl_print" | cut --delimiter=';' --fields=2)
HTTP code: $http_code
Page title: $page_title
Page extract:\n$page_extract" > $TEST_CONTEXT/curl_result
Expand Down
4 changes: 2 additions & 2 deletions lib/tests_coordination.sh
Expand Up @@ -4,7 +4,7 @@ source lib/lxc.sh
source lib/tests.sh
source lib/witness.sh

complete_log="./Complete.log"
readonly complete_log="./Complete-${WORKER_ID}.log"

# Purge some log files
rm -f "$complete_log" && touch "$complete_log"
Expand Down Expand Up @@ -295,7 +295,7 @@ run_all_tests() {
# Print the final results of the tests
log_title "Tests summary"

python3 lib/analyze_test_results.py $TEST_CONTEXT 2>./results.json
python3 lib/analyze_test_results.py $TEST_CONTEXT 2> ./results-${WORKER_ID}.json
[[ -e "$TEST_CONTEXT/summary.png" ]] && cp "$TEST_CONTEXT/summary.png" ./summary.png || rm -f summary.png

# Restore the started time for the timer
Expand Down