diff --git a/hscontrol/auth_test.go b/hscontrol/auth_test.go index 07032917..58dad28b 100644 --- a/hscontrol/auth_test.go +++ b/hscontrol/auth_test.go @@ -2507,7 +2507,7 @@ func TestAuthenticationFlows(t *testing.T) { if req.Followup != "" { var cancel context.CancelFunc - ctx, cancel = context.WithTimeout(context.Background(), 100*time.Millisecond) + ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second) defer cancel() } diff --git a/hscontrol/db/main_test.go b/hscontrol/db/main_test.go new file mode 100644 index 00000000..0a535fe4 --- /dev/null +++ b/hscontrol/db/main_test.go @@ -0,0 +1,25 @@ +package db + +import ( + "os" + "path/filepath" + "runtime" + "testing" +) + +// TestMain ensures the working directory is set to the package source directory +// so that relative testdata/ paths resolve correctly when the test binary is +// executed from an arbitrary location (e.g., via "go tool stress"). +func TestMain(m *testing.M) { + _, filename, _, ok := runtime.Caller(0) + if !ok { + panic("could not determine test source directory") + } + + err := os.Chdir(filepath.Dir(filename)) + if err != nil { + panic("could not chdir to test source directory: " + err.Error()) + } + + os.Exit(m.Run()) +} diff --git a/hscontrol/db/suite_test.go b/hscontrol/db/suite_test.go index 080d080b..a0e0bc6b 100644 --- a/hscontrol/db/suite_test.go +++ b/hscontrol/db/suite_test.go @@ -56,7 +56,7 @@ func newPostgresDBForTest(t *testing.T) *url.URL { srv, err := postgrestest.Start(ctx) if err != nil { - t.Fatal(err) + t.Skipf("start postgres: %s", err) } t.Cleanup(srv.Cleanup) diff --git a/hscontrol/policy/v2/main_test.go b/hscontrol/policy/v2/main_test.go new file mode 100644 index 00000000..00227588 --- /dev/null +++ b/hscontrol/policy/v2/main_test.go @@ -0,0 +1,25 @@ +package v2 + +import ( + "os" + "path/filepath" + "runtime" + "testing" +) + +// TestMain ensures the working directory is set to the package source directory +// so that relative testdata/ paths resolve correctly when the test binary is +// executed from an arbitrary location (e.g., via "go tool stress"). +func TestMain(m *testing.M) { + _, filename, _, ok := runtime.Caller(0) + if !ok { + panic("could not determine test source directory") + } + + err := os.Chdir(filepath.Dir(filename)) + if err != nil { + panic("could not chdir to test source directory: " + err.Error()) + } + + os.Exit(m.Run()) +} diff --git a/hscontrol/types/common.go b/hscontrol/types/common.go index a78278a4..5992a3a1 100644 --- a/hscontrol/types/common.go +++ b/hscontrol/types/common.go @@ -233,7 +233,7 @@ type AuthRequest struct { func NewAuthRequest() AuthRequest { return AuthRequest{ - finished: make(chan AuthVerdict), + finished: make(chan AuthVerdict, 1), closed: &atomic.Bool{}, } } @@ -241,7 +241,7 @@ func NewAuthRequest() AuthRequest { func NewRegisterAuthRequest(node Node) AuthRequest { return AuthRequest{ node: &node, - finished: make(chan AuthVerdict), + finished: make(chan AuthVerdict, 1), closed: &atomic.Bool{}, } } diff --git a/hscontrol/types/main_test.go b/hscontrol/types/main_test.go new file mode 100644 index 00000000..6835b05b --- /dev/null +++ b/hscontrol/types/main_test.go @@ -0,0 +1,25 @@ +package types + +import ( + "os" + "path/filepath" + "runtime" + "testing" +) + +// TestMain ensures the working directory is set to the package source directory +// so that relative testdata/ paths resolve correctly when the test binary is +// executed from an arbitrary location (e.g., via "go tool stress"). +func TestMain(m *testing.M) { + _, filename, _, ok := runtime.Caller(0) + if !ok { + panic("could not determine test source directory") + } + + err := os.Chdir(filepath.Dir(filename)) + if err != nil { + panic("could not chdir to test source directory: " + err.Error()) + } + + os.Exit(m.Run()) +}