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/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")
}

Loading…
Cancel
Save