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() {
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"
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"
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
}
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
}
}
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
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