tsweb: fix TestStdHandler_panic flake

Fixes #12816

Signed-off-by: Paul Scott <paul@tailscale.com>
This commit is contained in:
Paul Scott 2024-07-15 16:07:03 +01:00 committed by Paul Scott
parent 0834712c91
commit 014bf25c0a

View File

@ -14,7 +14,6 @@
"net/http/httptest"
"net/url"
"strings"
"sync/atomic"
"testing"
"time"
@ -546,15 +545,10 @@ func TestStdHandler_Panic(t *testing.T) {
// Run our panicking handler in a http.Server which catches and rethrows
// any panics.
var recovered atomic.Value
recovered := make(chan any, 1)
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer func() {
if r := recovered.Load(); r != nil {
panic(r)
}
}()
defer func() {
recovered.Store(recover())
recovered <- recover()
}()
h.ServeHTTP(w, r)
}))
@ -565,7 +559,7 @@ func TestStdHandler_Panic(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if recovered.Load() == nil {
if <-recovered == nil {
t.Fatal("expected panic but saw none")
}