]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Make secondary_http and secondary_redis tests independent
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 11 Jul 2021 19:51:49 +0000 (21:51 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 12 Jul 2021 20:42:42 +0000 (22:42 +0200)
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.

test/run
test/suites/secondary_http.bash
test/suites/secondary_redis.bash

index b6fa820692972d3fe830ff21105d1a8fba16ffb7..3cb51d60fecc75eacf098e8a09f6060fd00082de 100755 (executable)
--- 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 <<EOF
index b2887de9b92e36ab6616fe943c8c994adaf2f410..75bca7fd123541b19834dcc7b4ba8bcb58c00dd1 100644 (file)
@@ -1,11 +1,12 @@
 start_http_server() {
-    local host="127.0.0.1"
-    local port="8080"
-    SECONDARY_HTTP_URL="http://${host}:${port}/"
-
-    mkdir "secondary"
-    "${HTTP_SERVER}" --bind "${host}" --directory "secondary" "${port}" >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
 }
index cbaa2e0b1b14440f6d8ce8f096fe5beb9c9595a6..0e518bd09c63077fc3e3c7f33d10f4edc20cb519 100644 (file)
@@ -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