tsweb: fix TestStdHandler_panic flake

Fixes #12816

Signed-off-by: Paul Scott <paul@tailscale.com>
pull/12843/head
Paul Scott 4 months ago committed by Paul Scott
parent 0834712c91
commit 014bf25c0a

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

Loading…
Cancel
Save