From 29f68b5da600787f8dcf4d0b4bbaea85e7be371a Mon Sep 17 00:00:00 2001 From: Seebs Date: Mon, 26 Sep 2022 11:51:49 -0500 Subject: [PATCH] use testhook test cleanup The testhook post-test hooks only work if you use a TestMain to invoke them, otherwise the cleanups can be registered but never actually get run. This deletes the etcd sockets, and temp directories, that we created from our test runs. We also fix the test creating a temp file directly to create it in a TempDir (which gets cleaned up after the test), and fix the name of the top-level tests displayed in TestMain. --- client/logimport_test.go | 3 ++- client/main_test.go | 30 ++++++++++++++++++++++++++++++ main_test.go | 2 +- sql/main_test.go | 30 ++++++++++++++++++++++++++++++ sql3/main_test.go | 30 ++++++++++++++++++++++++++++++ sql3/planner/main_test.go | 30 ++++++++++++++++++++++++++++++ stats/main_test.go | 30 ++++++++++++++++++++++++++++++ test/main_test.go | 30 ++++++++++++++++++++++++++++++ 8 files changed, 183 insertions(+), 2 deletions(-) create mode 100644 client/main_test.go create mode 100644 sql/main_test.go create mode 100644 sql3/main_test.go create mode 100644 sql3/planner/main_test.go create mode 100644 stats/main_test.go create mode 100644 test/main_test.go diff --git a/client/logimport_test.go b/client/logimport_test.go index 51d736c50..ee0821222 100644 --- a/client/logimport_test.go +++ b/client/logimport_test.go @@ -92,7 +92,8 @@ func TestEncodeDecode(t *testing.T) { }) } - buf, err := os.CreateTemp("", "") + td := t.TempDir() + buf, err := os.CreateTemp(td, "") if err != nil { t.Fatalf("getting temp file: %v", err) } diff --git a/client/main_test.go b/client/main_test.go new file mode 100644 index 000000000..4d9cd99cd --- /dev/null +++ b/client/main_test.go @@ -0,0 +1,30 @@ +// Copyright 2021 Molecula Corp. All rights reserved. +package client_test + +import ( + "fmt" + "net" + "testing" + + "net/http" + _ "net/http/pprof" + + "github.com/molecula/featurebase/v3/testhook" +) + +func TestMain(m *testing.M) { + l, err := net.Listen("tcp", "localhost:0") + if err != nil { + panic(err) + } + port := l.Addr().(*net.TCPAddr).Port + fmt.Printf("client/ TestMain: online stack-traces: curl http://localhost:%v/debug/pprof/goroutine?debug=2\n", port) + go func() { + err := http.Serve(l, nil) + if err != nil { + panic(err) + } + }() + testhook.RunTestsWithHooks(m) + +} diff --git a/main_test.go b/main_test.go index e49f10ce8..393ee7628 100644 --- a/main_test.go +++ b/main_test.go @@ -19,7 +19,7 @@ func TestMain(m *testing.M) { panic(err) } port := l.Addr().(*net.TCPAddr).Port - fmt.Printf("pilosa/ TestMain: online stack-traces: curl http://localhost:%v/debug/pprof/goroutine?debug=2\n", port) + fmt.Printf("featurebase/ TestMain: online stack-traces: curl http://localhost:%v/debug/pprof/goroutine?debug=2\n", port) go func() { err := http.Serve(l, nil) if err != nil { diff --git a/sql/main_test.go b/sql/main_test.go new file mode 100644 index 000000000..99079412c --- /dev/null +++ b/sql/main_test.go @@ -0,0 +1,30 @@ +// Copyright 2021 Molecula Corp. All rights reserved. +package sql_test + +import ( + "fmt" + "net" + "testing" + + "net/http" + _ "net/http/pprof" + + "github.com/molecula/featurebase/v3/testhook" +) + +func TestMain(m *testing.M) { + l, err := net.Listen("tcp", "localhost:0") + if err != nil { + panic(err) + } + port := l.Addr().(*net.TCPAddr).Port + fmt.Printf("sql/ TestMain: online stack-traces: curl http://localhost:%v/debug/pprof/goroutine?debug=2\n", port) + go func() { + err := http.Serve(l, nil) + if err != nil { + panic(err) + } + }() + testhook.RunTestsWithHooks(m) + +} diff --git a/sql3/main_test.go b/sql3/main_test.go new file mode 100644 index 000000000..9412199d4 --- /dev/null +++ b/sql3/main_test.go @@ -0,0 +1,30 @@ +// Copyright 2021 Molecula Corp. All rights reserved. +package sql3_test + +import ( + "fmt" + "net" + "testing" + + "net/http" + _ "net/http/pprof" + + "github.com/molecula/featurebase/v3/testhook" +) + +func TestMain(m *testing.M) { + l, err := net.Listen("tcp", "localhost:0") + if err != nil { + panic(err) + } + port := l.Addr().(*net.TCPAddr).Port + fmt.Printf("sql3/ TestMain: online stack-traces: curl http://localhost:%v/debug/pprof/goroutine?debug=2\n", port) + go func() { + err := http.Serve(l, nil) + if err != nil { + panic(err) + } + }() + testhook.RunTestsWithHooks(m) + +} diff --git a/sql3/planner/main_test.go b/sql3/planner/main_test.go new file mode 100644 index 000000000..49993e6c9 --- /dev/null +++ b/sql3/planner/main_test.go @@ -0,0 +1,30 @@ +// Copyright 2021 Molecula Corp. All rights reserved. +package planner_test + +import ( + "fmt" + "net" + "testing" + + "net/http" + _ "net/http/pprof" + + "github.com/molecula/featurebase/v3/testhook" +) + +func TestMain(m *testing.M) { + l, err := net.Listen("tcp", "localhost:0") + if err != nil { + panic(err) + } + port := l.Addr().(*net.TCPAddr).Port + fmt.Printf("sql3/planner/ TestMain: online stack-traces: curl http://localhost:%v/debug/pprof/goroutine?debug=2\n", port) + go func() { + err := http.Serve(l, nil) + if err != nil { + panic(err) + } + }() + testhook.RunTestsWithHooks(m) + +} diff --git a/stats/main_test.go b/stats/main_test.go new file mode 100644 index 000000000..11b29175f --- /dev/null +++ b/stats/main_test.go @@ -0,0 +1,30 @@ +// Copyright 2021 Molecula Corp. All rights reserved. +package stats_test + +import ( + "fmt" + "net" + "testing" + + "net/http" + _ "net/http/pprof" + + "github.com/molecula/featurebase/v3/testhook" +) + +func TestMain(m *testing.M) { + l, err := net.Listen("tcp", "localhost:0") + if err != nil { + panic(err) + } + port := l.Addr().(*net.TCPAddr).Port + fmt.Printf("stats/ TestMain: online stack-traces: curl http://localhost:%v/debug/pprof/goroutine?debug=2\n", port) + go func() { + err := http.Serve(l, nil) + if err != nil { + panic(err) + } + }() + testhook.RunTestsWithHooks(m) + +} diff --git a/test/main_test.go b/test/main_test.go new file mode 100644 index 000000000..34b9c743d --- /dev/null +++ b/test/main_test.go @@ -0,0 +1,30 @@ +// Copyright 2021 Molecula Corp. All rights reserved. +package test_test + +import ( + "fmt" + "net" + "testing" + + "net/http" + _ "net/http/pprof" + + "github.com/molecula/featurebase/v3/testhook" +) + +func TestMain(m *testing.M) { + l, err := net.Listen("tcp", "localhost:0") + if err != nil { + panic(err) + } + port := l.Addr().(*net.TCPAddr).Port + fmt.Printf("test/ TestMain: online stack-traces: curl http://localhost:%v/debug/pprof/goroutine?debug=2\n", port) + go func() { + err := http.Serve(l, nil) + if err != nil { + panic(err) + } + }() + testhook.RunTestsWithHooks(m) + +}