From 25c664b13ab4c0c8498c4a1a448abee2b62bf3be Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Wed, 21 Jan 2015 23:59:08 +0000 Subject: [PATCH] Improvements to integration tests --- build.sh | 3 +++ test/logs/.gitignore | 1 + test/syncthingprocess.go | 2 +- test/util.go | 19 +++++++++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 test/logs/.gitignore diff --git a/build.sh b/build.sh index b88241320..aaaea87c0 100755 --- a/build.sh +++ b/build.sh @@ -3,6 +3,7 @@ set -euo pipefail IFS=$'\n\t' DOCKERIMGV=1.4.1-1 +STTRACE=${STTRACE:-} case "${1:-default}" in default) @@ -110,6 +111,7 @@ case "${1:-default}" in docker run --rm -h syncthing-builder -u $(id -u) -t \ -v $(pwd):/go/src/github.com/syncthing/syncthing \ -w /go/src/github.com/syncthing/syncthing \ + -e "STTRACE=$STTRACE" \ syncthing/build:$DOCKERIMGV \ sh -c './build.sh clean \ && go vet ./cmd/... ./internal/... \ @@ -122,6 +124,7 @@ case "${1:-default}" in docker run --rm -h syncthing-builder -u $(id -u) -t \ -v $(pwd):/go/src/github.com/syncthing/syncthing \ -w /go/src/github.com/syncthing/syncthing \ + -e "STTRACE=$STTRACE" \ syncthing/build:$DOCKERIMGV \ sh -euxc './build.sh clean \ && go run build.go -race \ diff --git a/test/logs/.gitignore b/test/logs/.gitignore new file mode 100644 index 000000000..f47cb2045 --- /dev/null +++ b/test/logs/.gitignore @@ -0,0 +1 @@ +*.out diff --git a/test/syncthingprocess.go b/test/syncthingprocess.go index 043a2f662..3943e6e00 100644 --- a/test/syncthingprocess.go +++ b/test/syncthingprocess.go @@ -50,7 +50,7 @@ type syncthingProcess struct { func (p *syncthingProcess) start() error { if p.logfd == nil { - logfd, err := os.Create(p.instance + ".out") + logfd, err := os.Create("logs/" + getTestName() + "-" + p.instance + ".out") if err != nil { return err } diff --git a/test/util.go b/test/util.go index 76edf694e..f3c21dfeb 100644 --- a/test/util.go +++ b/test/util.go @@ -27,6 +27,7 @@ import ( "math/rand" "os" "path/filepath" + "runtime" "sort" "strings" "time" @@ -441,3 +442,21 @@ func isTimeout(err error) bool { return strings.Contains(err.Error(), "use of closed network connection") || strings.Contains(err.Error(), "request cancelled while waiting") } + +func getTestName() string { + callers := make([]uintptr, 100) + runtime.Callers(1, callers) + for i, caller := range callers { + f := runtime.FuncForPC(caller) + if f != nil { + if f.Name() == "testing.tRunner" { + testf := runtime.FuncForPC(callers[i-1]) + if testf != nil { + path := strings.Split(testf.Name(), ".") + return path[len(path)-1] + } + } + } + } + return time.Now().String() +}