Skip to content

Commit

Permalink
test: fix flaky test 'failed: should find no corresponding process' (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
spacewander authored Sep 25, 2022
1 parent 1d29d4b commit 3bbc7ae
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 88 deletions.
109 changes: 109 additions & 0 deletions t/cli/test_cmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/usr/bin/env bash

#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

. ./t/cli/common.sh

git checkout conf/config.yaml

# check restart with old nginx.pid exist
echo "-1" > logs/nginx.pid
out=$(./bin/apisix start 2>&1 || true)
if echo "$out" | grep "APISIX is running"; then
rm logs/nginx.pid
echo "failed: should reject bad nginx.pid"
exit 1
fi

./bin/apisix stop
sleep 0.5
rm logs/nginx.pid || true

# check no corresponding process
make run
oldpid=$(< logs/nginx.pid)
make stop
sleep 0.5
echo $oldpid > logs/nginx.pid
out=$(make run || true)
if ! echo "$out" | grep "nginx.pid exists but there's no corresponding process with pid"; then
echo "failed: should find no corresponding process"
exit 1
fi
make stop
echo "pass: no corresponding process"

# check running when run repeatedly
out=$(make run; make run || true)
if ! echo "$out" | grep "APISIX is running"; then
echo "failed: should find APISIX running"
exit 1
fi

make stop
echo "pass: check APISIX running"

# check customized config.yaml is copied and reverted.

git checkout conf/config.yaml

echo "
deployment:
admin:
admin_listen:
port: 9180
https_admin: true
admin_api_mtls:
admin_ssl_cert: '../t/certs/apisix_admin_ssl.crt'
admin_ssl_cert_key: '../t/certs/apisix_admin_ssl.key'
" > conf/customized_config.yaml

cp conf/config.yaml conf/config_original.yaml

make init

if ./bin/apisix start -c conf/not_existed_config.yaml; then
echo "failed: apisix still start with invalid customized config.yaml"
exit 1
fi

./bin/apisix start -c conf/customized_config.yaml

if cmp -s "conf/config.yaml" "conf/config_original.yaml"; then
rm conf/config_original.yaml
echo "failed: customized config.yaml copied failed"
exit 1
fi

code=$(curl -k -i -m 20 -o /dev/null -s -w %{http_code} https://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1')
if [ ! $code -eq 200 ]; then
rm conf/config_original.yaml conf/customized_config.yaml
echo "failed: customized config.yaml not be used"
exit 1
fi

make stop

if ! cmp -s "conf/config.yaml" "conf/config_original.yaml"; then
rm conf/config_original.yaml conf/customized_config.yaml
echo "failed: customized config.yaml reverted failed"
exit 1
fi

rm conf/config_original.yaml conf/customized_config.yaml
echo "passed: customized config.yaml copied and reverted succeeded"
89 changes: 1 addition & 88 deletions t/cli/test_main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -520,56 +520,6 @@ fi
sed -i 's/worker_processes: 2/worker_processes: auto/' conf/config.yaml
echo "passed: worker_processes number is configurable"

# check customized config.yaml is copied and reverted.

git checkout conf/config.yaml

echo "
deployment:
admin:
admin_listen:
port: 9180
https_admin: true
admin_api_mtls:
admin_ssl_cert: '../t/certs/apisix_admin_ssl.crt'
admin_ssl_cert_key: '../t/certs/apisix_admin_ssl.key'
" > conf/customized_config.yaml

cp conf/config.yaml conf/config_original.yaml

make init

if ./bin/apisix start -c conf/not_existed_config.yaml; then
echo "failed: apisix still start with invalid customized config.yaml"
exit 1
fi

./bin/apisix start -c conf/customized_config.yaml

if cmp -s "conf/config.yaml" "conf/config_original.yaml"; then
rm conf/config_original.yaml
echo "failed: customized config.yaml copied failed"
exit 1
fi

code=$(curl -k -i -m 20 -o /dev/null -s -w %{http_code} https://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1')
if [ ! $code -eq 200 ]; then
rm conf/config_original.yaml conf/customized_config.yaml
echo "failed: customized config.yaml not be used"
exit 1
fi

make stop

if ! cmp -s "conf/config.yaml" "conf/config_original.yaml"; then
rm conf/config_original.yaml conf/customized_config.yaml
echo "failed: customized config.yaml reverted failed"
exit 1
fi

rm conf/config_original.yaml conf/customized_config.yaml
echo "passed: customized config.yaml copied and reverted succeeded"

# check disable cpu affinity
git checkout conf/config.yaml

Expand Down Expand Up @@ -641,7 +591,7 @@ stream_plugins:
- 3rd-party
' > conf/config.yaml

rm logs/error.log
rm logs/error.log || true
make init
make run

Expand Down Expand Up @@ -711,43 +661,6 @@ fi

echo "passed: hook can take effect"

# check restart with old nginx.pid exist
echo "-1" > logs/nginx.pid
out=$(./bin/apisix start 2>&1 || true)
if echo "$out" | grep "APISIX is running"; then
rm logs/nginx.pid
echo "failed: should reject bad nginx.pid"
exit 1
fi

./bin/apisix stop
sleep 0.5
rm logs/nginx.pid || true

# check no corresponding process
make run
oldpid=$(< logs/nginx.pid)
make stop
sleep 0.5
echo $oldpid > logs/nginx.pid
out=$(make run || true)
if ! echo "$out" | grep "nginx.pid exists but there's no corresponding process with pid"; then
echo "failed: should find no corresponding process"
exit 1
fi
make stop
echo "pass: no corresponding process"

# check running when run repeatedly
out=$(make run; make run || true)
if ! echo "$out" | grep "APISIX is running"; then
echo "failed: should find APISIX running"
exit 1
fi

make stop
echo "pass: check APISIX running"

# check the keepalive related parameter settings in the upstream
git checkout conf/config.yaml

Expand Down

0 comments on commit 3bbc7ae

Please sign in to comment.