mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-30 05:22:44 -08:00
tstest/integration: fail tests when tailscaled logs an [unexpected] line
tailscaled uses the [unexpected] log prefix for conditions that should never happen. Record such lines as the log catcher receives them and report each one as a test error when the test environment shuts down. Run tailscaled with IN_TS_TEST=1 so logs are uploaded as they are written, rather than batched every two seconds and partly lost when the process is killed at the end of the test. Updates #22307 Signed-off-by: Nick Khyl <[email protected]>
This commit is contained in:
1 file changed
+18
@@ -404,6 +404,8 @@ type LogCatcher struct {
|
||||
gotErr error
|
||||
reqs int
|
||||
raw bool // indicates whether to store the raw JSON logs uploaded, instead of just the text
|
||||
|
||||
unexpected []string // log lines containing "[unexpected]"
|
||||
}
|
||||
|
||||
// UseLogf makes the logcatcher implementation use a given logf function
|
||||
@@ -427,6 +429,15 @@ func (lc *LogCatcher) logsContains(sub mem.RO) bool {
|
||||
return mem.Contains(mem.B(lc.buf.Bytes()), sub)
|
||||
}
|
||||
|
||||
// unexpectedLines returns the captured log lines that contain
|
||||
// "[unexpected]", which tailscaled uses to flag conditions that
|
||||
// should never happen.
|
||||
func (lc *LogCatcher) unexpectedLines() []string {
|
||||
lc.mu.Lock()
|
||||
defer lc.mu.Unlock()
|
||||
return lc.unexpected
|
||||
}
|
||||
|
||||
func (lc *LogCatcher) numRequests() int {
|
||||
lc.mu.Lock()
|
||||
defer lc.mu.Unlock()
|
||||
@@ -512,6 +523,9 @@ func (lc *LogCatcher) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
} else {
|
||||
id := privID.Public().String()[:3] // good enough for integration tests
|
||||
for _, ent := range jreq {
|
||||
if strings.Contains(ent.Text, "[unexpected]") {
|
||||
lc.unexpected = append(lc.unexpected, strings.TrimSpace(ent.Text))
|
||||
}
|
||||
if lc.raw {
|
||||
lc.buf.Write(bodyBytes)
|
||||
continue
|
||||
@@ -600,6 +614,9 @@ func NewTestEnv(t testing.TB, opts ...TestEnvOpt) *TestEnv {
|
||||
e.t.Errorf("traffic trap: %v", err)
|
||||
e.t.Logf("logs: %s", e.LogCatcher.logsString())
|
||||
}
|
||||
for _, line := range e.LogCatcher.unexpectedLines() {
|
||||
e.t.Errorf("tailscaled logged: %s", line)
|
||||
}
|
||||
e.LogCatcherServer.Close()
|
||||
e.TrafficTrapServer.Close()
|
||||
e.ControlServer.Close()
|
||||
@@ -953,6 +970,7 @@ func (n *TestNode) daemonEnv(ipnGOOS string) []string {
|
||||
"TS_PANIC_IF_HIT_MAIN_CONTROL=1",
|
||||
"TS_DISABLE_PORTMAPPER=1", // shouldn't be needed; test is all localhost
|
||||
"TS_DEBUG_LOG_RATE=all",
|
||||
"IN_TS_TEST=1", // upload logs immediately, so the LogCatcher sees them before the test ends; skip external network probes
|
||||
}
|
||||
if n.allowUpdates {
|
||||
env = append(env, "TS_TEST_ALLOW_AUTO_UPDATE=1")
|
||||
|
||||
Reference in new issue
Block a user