From: Joel Rosdahl Date: Sun, 11 Jul 2021 19:51:49 +0000 (+0200) Subject: Make secondary_http and secondary_redis tests independent X-Git-Tag: v4.4~135 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=82e3ff02731d2e981160405debcdecc6e352be63;p=thirdparty%2Fccache.git Make secondary_http and secondary_redis tests independent Instead of starting an HTTP or Redis server that lives for the duration of the test suite, start a new one for each test case. This makes tests more independent and also opens up for future testing of e.g. different ports and authentication modes by allowing different server configurations for each test case. --- diff --git a/test/run b/test/run index b6fa82069..3cb51d60f 100755 --- a/test/run +++ b/test/run @@ -416,6 +416,7 @@ TEST() { CURRENT_TEST=$1 CCACHE_COMPILE="$CCACHE $COMPILER" + terminate_all_children reset_environment if $verbose; then @@ -443,7 +444,7 @@ TEST() { export LC_ALL=C -trap 'terminate_all_children' EXIT # also cleanup after exceptional code flow +trap terminate_all_children EXIT # also clean up after exceptional code flow if pwd | grep '[^A-Za-z0-9/.,=_%+-]' >/dev/null 2>&1; then cat <http-server.log 2>&1 & - "${HTTP_CLIENT}" "${SECONDARY_HTTP_URL}" >http-client.log 2>&1 || test_failed_internal "Cannot connect to server" + local port="$1" + local cache_dir="$2" + + mkdir -p "${cache_dir}" + "${HTTP_SERVER}" --bind localhost --directory "${cache_dir}" "${port}" \ + &>http-server.log & + "${HTTP_CLIENT}" "http://localhost:${port}" &>http-client.log \ + || test_failed_internal "Cannot connect to server" } SUITE_secondary_http_PROBE() { @@ -17,42 +18,38 @@ SUITE_secondary_http_PROBE() { SUITE_secondary_http_SETUP() { unset CCACHE_NODIRECT - local subdir="${CURRENT_TEST// /_}" - export CCACHE_SECONDARY_STORAGE="${SECONDARY_HTTP_URL}/${subdir}" - SECONDARY_HTTP_DIR="${ABS_TESTDIR}/secondary/${subdir}" - mkdir "${SECONDARY_HTTP_DIR}" - generate_code 1 test.c } SUITE_secondary_http() { - start_http_server - # ------------------------------------------------------------------------- TEST "Base case" + start_http_server 12780 secondary + export CCACHE_SECONDARY_STORAGE="http://localhost:12780" + $CCACHE_COMPILE -c test.c expect_stat 'cache hit (direct)' 0 expect_stat 'cache miss' 1 expect_stat 'files in cache' 2 - expect_file_count 2 '*' $SECONDARY_HTTP_DIR # result + manifest + expect_file_count 2 '*' secondary # result + manifest $CCACHE_COMPILE -c test.c expect_stat 'cache hit (direct)' 1 expect_stat 'cache miss' 1 expect_stat 'files in cache' 2 - expect_file_count 2 '*' $SECONDARY_HTTP_DIR # result + manifest + expect_file_count 2 '*' secondary # result + manifest $CCACHE -C >/dev/null expect_stat 'files in cache' 0 - expect_file_count 2 '*' $SECONDARY_HTTP_DIR # result + manifest + expect_file_count 2 '*' secondary # result + manifest $CCACHE_COMPILE -c test.c expect_stat 'cache hit (direct)' 2 expect_stat 'cache miss' 1 expect_stat 'files in cache' 0 expect_stat 'files in cache' 0 - expect_file_count 2 '*' $SECONDARY_HTTP_DIR # result + manifest + expect_file_count 2 '*' secondary # result + manifest # ------------------------------------------------------------------------- TEST "Read-only" @@ -61,11 +58,11 @@ SUITE_secondary_http() { expect_stat 'cache hit (direct)' 0 expect_stat 'cache miss' 1 expect_stat 'files in cache' 2 - expect_file_count 2 '*' $SECONDARY_HTTP_DIR # result + manifest + expect_file_count 2 '*' secondary # result + manifest $CCACHE -C >/dev/null expect_stat 'files in cache' 0 - expect_file_count 2 '*' $SECONDARY_HTTP_DIR # result + manifest + expect_file_count 2 '*' secondary # result + manifest CCACHE_SECONDARY_STORAGE+="|read-only" @@ -73,12 +70,12 @@ SUITE_secondary_http() { expect_stat 'cache hit (direct)' 1 expect_stat 'cache miss' 1 expect_stat 'files in cache' 0 - expect_file_count 2 '*' $SECONDARY_HTTP_DIR # result + manifest + expect_file_count 2 '*' secondary # result + manifest echo 'int x;' >> test.c $CCACHE_COMPILE -c test.c expect_stat 'cache hit (direct)' 1 expect_stat 'cache miss' 2 expect_stat 'files in cache' 2 - expect_file_count 2 '*' $SECONDARY_HTTP_DIR # result + manifest + expect_file_count 2 '*' secondary # result + manifest } diff --git a/test/suites/secondary_redis.bash b/test/suites/secondary_redis.bash index cbaa2e0b1..0e518bd09 100644 --- a/test/suites/secondary_redis.bash +++ b/test/suites/secondary_redis.bash @@ -9,11 +9,24 @@ SUITE_secondary_redis_PROBE() { fi } -SUITE_secondary_redis_SETUP() { - redis_url=redis://localhost:7777 +start_redis_server() { + local port="$1" + + if ! command -v timeout >/dev/null; then + timeout() { perl -e 'alarm shift; exec @ARGV' "$@"; } + fi + + timeout 10 redis-server --bind localhost --port "${port}" >/dev/null & + # Wait for server start. + i=0 + while [ $i -lt 100 ] && ! redis-cli -p "${port}" ping &>/dev/null; do + sleep 0.1 + i=$((i + 1)) + done +} +SUITE_secondary_redis_SETUP() { unset CCACHE_NODIRECT - export CCACHE_SECONDARY_STORAGE="$redis_url" generate_code 1 test.c } @@ -30,22 +43,15 @@ expect_number_of_redis_cache_entries() { } SUITE_secondary_redis() { - if ! command -v timeout >/dev/null; then - timeout() { perl -e 'alarm shift; exec @ARGV' "$@"; } - fi - - timeout 10 redis-server --bind localhost --port 7777 >/dev/null & - - # Wait for boot. - i=0 - while [ $i -lt 100 ] && ! redis-cli -p 7777 ping >&/dev/null; do - sleep 0.1 - i=$((i + 1)) - done - # ------------------------------------------------------------------------- TEST "Base case" + port=7777 + redis_url="redis://localhost:${port}" + export CCACHE_SECONDARY_STORAGE="${redis_url}" + + start_redis_server "${port}" + $CCACHE_COMPILE -c test.c expect_stat 'cache hit (direct)' 0 expect_stat 'cache miss' 1 @@ -68,11 +74,15 @@ SUITE_secondary_redis() { expect_stat 'files in cache' 0 expect_number_of_redis_cache_entries 2 "$redis_url" # result + manifest - redis-cli -p 7777 flushdb >/dev/null - # ------------------------------------------------------------------------- TEST "Read-only" + port=7777 + redis_url="redis://localhost:${port}" + export CCACHE_SECONDARY_STORAGE="${redis_url}" + + start_redis_server "${port}" + $CCACHE_COMPILE -c test.c expect_stat 'cache hit (direct)' 0 expect_stat 'cache miss' 1