mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
tsweb: fix TestStdHandler_panic flake
Fixes #12816 Signed-off-by: Paul Scott <paul@tailscale.com>
This commit is contained in:
parent
0834712c91
commit
014bf25c0a
@ -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")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user