mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-19 19:38:40 +00:00
control/controlhttp: remove tstest.Clock from tests (#8830)
These specific tests rely on some timers in the controlhttp code. Without time moving forward and timers triggering, the tests fail. Updates #8587 Signed-off-by: Andrew Lytvynov <awly@tailscale.com>
This commit is contained in:
parent
3d2e35c053
commit
90081a25ca
@ -26,6 +26,7 @@ import (
|
|||||||
"tailscale.com/net/tsdial"
|
"tailscale.com/net/tsdial"
|
||||||
"tailscale.com/tailcfg"
|
"tailscale.com/tailcfg"
|
||||||
"tailscale.com/tstest"
|
"tailscale.com/tstest"
|
||||||
|
"tailscale.com/tstime"
|
||||||
"tailscale.com/types/key"
|
"tailscale.com/types/key"
|
||||||
"tailscale.com/types/logger"
|
"tailscale.com/types/logger"
|
||||||
)
|
)
|
||||||
@ -172,8 +173,12 @@ func testControlHTTP(t *testing.T, param httpTestParam) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var httpHandler http.Handler = handler
|
var httpHandler http.Handler = handler
|
||||||
|
const fallbackDelay = 50 * time.Millisecond
|
||||||
|
clock := tstest.NewClock(tstest.ClockOpts{Step: 2 * fallbackDelay})
|
||||||
|
// Advance once to init the clock.
|
||||||
|
clock.Now()
|
||||||
if param.makeHTTPHangAfterUpgrade {
|
if param.makeHTTPHangAfterUpgrade {
|
||||||
httpHandler = http.HandlerFunc(brokenMITMHandler)
|
httpHandler = brokenMITMHandler(clock)
|
||||||
}
|
}
|
||||||
httpServer := &http.Server{Handler: httpHandler}
|
httpServer := &http.Server{Handler: httpHandler}
|
||||||
go httpServer.Serve(httpLn)
|
go httpServer.Serve(httpLn)
|
||||||
@ -204,8 +209,8 @@ func testControlHTTP(t *testing.T, param httpTestParam) {
|
|||||||
Dialer: new(tsdial.Dialer).SystemDial,
|
Dialer: new(tsdial.Dialer).SystemDial,
|
||||||
Logf: t.Logf,
|
Logf: t.Logf,
|
||||||
omitCertErrorLogging: true,
|
omitCertErrorLogging: true,
|
||||||
testFallbackDelay: 50 * time.Millisecond,
|
testFallbackDelay: fallbackDelay,
|
||||||
Clock: &tstest.Clock{},
|
Clock: clock,
|
||||||
}
|
}
|
||||||
|
|
||||||
if proxy != nil {
|
if proxy != nil {
|
||||||
@ -471,12 +476,16 @@ EKTcWGekdmdDPsHloRNtsiCa697B2O9IFA==
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func brokenMITMHandler(w http.ResponseWriter, r *http.Request) {
|
func brokenMITMHandler(clock tstime.Clock) http.HandlerFunc {
|
||||||
w.Header().Set("Upgrade", upgradeHeaderValue)
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Connection", "upgrade")
|
w.Header().Set("Upgrade", upgradeHeaderValue)
|
||||||
w.WriteHeader(http.StatusSwitchingProtocols)
|
w.Header().Set("Connection", "upgrade")
|
||||||
w.(http.Flusher).Flush()
|
w.WriteHeader(http.StatusSwitchingProtocols)
|
||||||
<-r.Context().Done()
|
w.(http.Flusher).Flush()
|
||||||
|
// Advance the clock to trigger HTTPs fallback.
|
||||||
|
clock.Now()
|
||||||
|
<-r.Context().Done()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDialPlan(t *testing.T) {
|
func TestDialPlan(t *testing.T) {
|
||||||
@ -621,12 +630,15 @@ func TestDialPlan(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, tt := range testCases {
|
for _, tt := range testCases {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
// TODO(awly): replace this with tstest.NewClock and update the
|
||||||
|
// test to advance the clock correctly.
|
||||||
|
clock := tstime.StdClock{}
|
||||||
makeHandler(t, "fallback", fallbackAddr, nil)
|
makeHandler(t, "fallback", fallbackAddr, nil)
|
||||||
makeHandler(t, "good", goodAddr, nil)
|
makeHandler(t, "good", goodAddr, nil)
|
||||||
makeHandler(t, "other", otherAddr, nil)
|
makeHandler(t, "other", otherAddr, nil)
|
||||||
makeHandler(t, "other2", other2Addr, nil)
|
makeHandler(t, "other2", other2Addr, nil)
|
||||||
makeHandler(t, "broken", brokenAddr, func(h http.Handler) http.Handler {
|
makeHandler(t, "broken", brokenAddr, func(h http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(brokenMITMHandler)
|
return brokenMITMHandler(clock)
|
||||||
})
|
})
|
||||||
|
|
||||||
dialer := closeTrackDialer{
|
dialer := closeTrackDialer{
|
||||||
@ -662,7 +674,7 @@ func TestDialPlan(t *testing.T) {
|
|||||||
drainFinished: drained,
|
drainFinished: drained,
|
||||||
omitCertErrorLogging: true,
|
omitCertErrorLogging: true,
|
||||||
testFallbackDelay: 50 * time.Millisecond,
|
testFallbackDelay: 50 * time.Millisecond,
|
||||||
Clock: &tstest.Clock{},
|
Clock: clock,
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, err := a.dial(ctx)
|
conn, err := a.dial(ctx)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user