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.
This commit is contained in:
Seebs 2022-09-26 11:51:49 -05:00 committed by seebs
parent 3582cee4b6
commit 9c216ef8a6
8 changed files with 183 additions and 2 deletions

View file

@ -91,7 +91,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)
}

30
client/main_test.go Normal file
View file

@ -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)
}

View file

@ -18,7 +18,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 {

30
sql/main_test.go Normal file
View file

@ -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)
}

30
sql3/main_test.go Normal file
View file

@ -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)
}

30
sql3/planner/main_test.go Normal file
View file

@ -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)
}

30
stats/main_test.go Normal file
View file

@ -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)
}

30
test/main_test.go Normal file
View file

@ -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)
}