2020-02-05 22:16:58 +00:00
|
|
|
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package wgengine
|
|
|
|
|
|
|
|
import (
|
2021-03-27 15:10:26 +00:00
|
|
|
"runtime"
|
2020-02-05 22:16:58 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestWatchdog(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2021-03-27 15:10:26 +00:00
|
|
|
var maxWaitMultiple time.Duration = 1
|
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
// Work around slow close syscalls on Big Sur with content filter Network Extensions installed.
|
|
|
|
// See https://github.com/tailscale/tailscale/issues/1598.
|
|
|
|
maxWaitMultiple = 15
|
|
|
|
}
|
|
|
|
|
2020-02-05 22:16:58 +00:00
|
|
|
t.Run("default watchdog does not fire", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
2021-03-01 18:08:53 +00:00
|
|
|
e, err := NewFakeUserspaceEngine(t.Logf, 0)
|
2020-02-05 22:16:58 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
e = NewWatchdog(e)
|
2021-03-27 15:10:26 +00:00
|
|
|
e.(*watchdogEngine).maxWait = maxWaitMultiple * 150 * time.Millisecond
|
2020-07-03 08:00:45 +01:00
|
|
|
e.(*watchdogEngine).logf = t.Logf
|
|
|
|
e.(*watchdogEngine).fatalf = t.Fatalf
|
2020-02-05 22:16:58 +00:00
|
|
|
|
|
|
|
e.RequestStatus()
|
|
|
|
e.RequestStatus()
|
|
|
|
e.RequestStatus()
|
|
|
|
e.Close()
|
|
|
|
})
|
|
|
|
}
|