From 8fb5a3e565423d73fd02f19dc17a0bc9daf3f179 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Thu, 22 Jun 2023 10:01:17 +0200 Subject: [PATCH] add script to run integration tests Signed-off-by: Kristoffer Dalby --- flake.nix | 1 + hscontrol/poll.go | 2 -- integration/run.sh | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100755 integration/run.sh diff --git a/flake.nix b/flake.nix index 11fdbb47c5..49df6ffa80 100644 --- a/flake.nix +++ b/flake.nix @@ -96,6 +96,7 @@ nfpm gotestsum gotests + ksh # 'dot' is needed for pprof graphs # go tool pprof -http=: diff --git a/hscontrol/poll.go b/hscontrol/poll.go index eaf759d123..937caee858 100644 --- a/hscontrol/poll.go +++ b/hscontrol/poll.go @@ -64,8 +64,6 @@ func (h *Headscale) handlePoll( ) { logInfo, logErr := logPollFunc(mapRequest, machine, isNoise) - // TODO(kradalby): This is a stepping stone, mapper should be initiated once - // per client or something similar mapp := mapper.NewMapper( h.db, h.privateKey2019, diff --git a/integration/run.sh b/integration/run.sh new file mode 100755 index 0000000000..ded53f6557 --- /dev/null +++ b/integration/run.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env ksh + +run_tests() { + test_name=$1 + num_tests=$2 + + success_count=0 + failure_count=0 + runtimes=() + + echo "-------------------" + echo "Running Tests for $test_name" + + for ((i = 1; i <= num_tests; i++)); do + ocker network prune -f >/dev/null 2>&1 + + start=$(date +%s) + docker run \ + --tty --rm \ + --volume ~/.cache/hs-integration-go:/go \ + --name headscale-test-suite \ + --volume "$PWD:$PWD" -w "$PWD"/integration \ + --volume /var/run/docker.sock:/var/run/docker.sock \ + --volume "$PWD"/control_logs:/tmp/control \ + golang:1 \ + go test ./... \ + -tags ts2019 \ + -failfast \ + -timeout 120m \ + -parallel 1 \ + -run "^$test_name\$" >/dev/null 2>&1 + status=$? + end=$(date +%s) + + runtime=$((end - start)) + runtimes+=("$runtime") + + if [ "$status" -eq 0 ]; then + ((success_count++)) + else + ((failure_count++)) + fi + done + + echo "-------------------" + echo "Test Summary for $test_name" + echo "-------------------" + echo "Total Tests: $num_tests" + echo "Successful Tests: $success_count" + echo "Failed Tests: $failure_count" + echo "Runtimes in seconds: ${runtimes[*]}" + echo +} + +# Check if both arguments are provided +if [ $# -ne 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +test_name=$1 +num_tests=$2 + +docker network prune -f + +if [ "$test_name" = "all" ]; then + rg --regexp "func (Test.+)\(.*" ./integration/ --replace '$1' --no-line-number --no-filename --no-heading | sort | while read -r test_name; do + run_tests "$test_name" "$num_tests" + done +else + run_tests "$test_name" "$num_tests" +fi