A process count below zero was accepted and stored verbatim, leaving the scheduler to reject the value long after the command reported success. Counts below zero are now rejected, as are process tuples that omit a process type, across `ps:scale`, the `ps-set-scale` trigger and the `formation` key of `app.json`. A negative count persisted by an earlier version stays readable so it can be corrected with `ps:scale`.
117 lines
2.9 KiB
Bash
117 lines
2.9 KiB
Bash
#!/usr/bin/env bats
|
|
load test_helper
|
|
|
|
setup() {
|
|
global_setup
|
|
create_app
|
|
}
|
|
|
|
teardown() {
|
|
destroy_app
|
|
global_teardown
|
|
}
|
|
|
|
@test "(app-json) persist scale" {
|
|
local CUSTOM_TMP=$(mktemp -d "/tmp/${DOKKU_DOMAIN}.XXXXX")
|
|
trap 'popd &>/dev/null || true; rm -rf "$TMP"' INT TERM
|
|
|
|
CUSTOM_TMP="$CUSTOM_TMP" run deploy_app python "dokku@$DOKKU_DOMAIN:$TEST_APP" persist_scale_callback_a
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run /bin/bash -c "dokku --quiet ps:scale $TEST_APP"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
assert_output_contains "web: 1"
|
|
assert_output_contains "worker: 1"
|
|
assert_output_contains "cron: 0" 0
|
|
|
|
run persist_scale_callback_b "$TEST_APP" "$CUSTOM_TMP"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run git -C "$CUSTOM_TMP" add app.json Procfile
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run git -C "$CUSTOM_TMP" commit -m 'Update scaling parameters'
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run git -C "$CUSTOM_TMP" push target master:master
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run /bin/bash -c "dokku --quiet ps:scale $TEST_APP"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
assert_output_contains "web: 1"
|
|
assert_output_contains "worker: 1" 0
|
|
assert_output_contains "worker: 0" 0
|
|
assert_output_contains "cron: 1" 1
|
|
}
|
|
|
|
@test "(app-json) negative formation quantity" {
|
|
mkdir -p /var/lib/dokku/data/app-json/$TEST_APP
|
|
negative_formation_callback "$TEST_APP" /var/lib/dokku/data/app-json/$TEST_APP
|
|
|
|
run_plugn_trigger post-release-builder herokuish $TEST_APP dokku/$TEST_APP:latest
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_failure
|
|
assert_output_contains "Invalid quantity for process type web in app.json: value must be zero or greater"
|
|
|
|
run /bin/bash -c "dokku --quiet ps:scale $TEST_APP"
|
|
output=$(echo "$output" | tr -s " ")
|
|
echo "output: ($output)"
|
|
echo "status: $status"
|
|
assert_output "web: 1"
|
|
}
|
|
|
|
persist_scale_callback_a() {
|
|
local APP="$1"
|
|
local APP_REPO_DIR="$2"
|
|
[[ -z "$APP" ]] && local APP="$TEST_APP"
|
|
|
|
rm "$APP_REPO_DIR/Procfile"
|
|
touch "$APP_REPO_DIR/Procfile"
|
|
echo "web: python3 web.py" >>"$APP_REPO_DIR/Procfile"
|
|
echo "worker: python3 worker.py" >>"$APP_REPO_DIR/Procfile"
|
|
mv "$APP_REPO_DIR/app-5205a.json" "$APP_REPO_DIR/app.json"
|
|
}
|
|
|
|
persist_scale_callback_b() {
|
|
local APP="$1"
|
|
local APP_REPO_DIR="$2"
|
|
[[ -z "$APP" ]] && local APP="$TEST_APP"
|
|
|
|
rm "$APP_REPO_DIR/Procfile"
|
|
touch "$APP_REPO_DIR/Procfile"
|
|
echo "web: python3 web.py" >>"$APP_REPO_DIR/Procfile"
|
|
echo "cron: python3 worker.py" >>"$APP_REPO_DIR/Procfile"
|
|
mv "$APP_REPO_DIR/app-5205b.json" "$APP_REPO_DIR/app.json"
|
|
}
|
|
|
|
negative_formation_callback() {
|
|
local APP="$1"
|
|
local APP_REPO_DIR="$2"
|
|
[[ -z "$APP" ]] && local APP="$TEST_APP"
|
|
|
|
cat >"$APP_REPO_DIR/app.json" <<EOF
|
|
{
|
|
"formation": {
|
|
"web": {
|
|
"quantity": -1
|
|
}
|
|
}
|
|
}
|
|
EOF
|
|
}
|