diff --git a/ipn/loglines_test.go b/ipn/loglines_test.go index 0ea12d386..75e830dc0 100644 --- a/ipn/loglines_test.go +++ b/ipn/loglines_test.go @@ -26,6 +26,7 @@ func TestLocalLogLines(t *testing.T) { "[v1] peer keys: %s", "[v1] v%v peers: %v", }) + defer logListen.Close() logid := func(hex byte) logtail.PublicID { var ret logtail.PublicID diff --git a/tstest/log.go b/tstest/log.go index 7b6ac2b47..b7750cf12 100644 --- a/tstest/log.go +++ b/tstest/log.go @@ -75,13 +75,18 @@ type LogLineTracker struct { logf logger.Logf listenFor []string - mu sync.Mutex - seen map[string]bool // format string => false (if not yet seen but wanted) or true (once seen) + mu sync.Mutex + closed bool + seen map[string]bool // format string => false (if not yet seen but wanted) or true (once seen) } // Logf logs to its underlying logger and also tracks that the given format pattern has been seen. func (lt *LogLineTracker) Logf(format string, args ...interface{}) { lt.mu.Lock() + if lt.closed { + lt.mu.Unlock() + return + } if v, ok := lt.seen[format]; ok && !v { lt.seen[format] = true } @@ -101,3 +106,10 @@ func (lt *LogLineTracker) Check() []string { } return notSeen } + +// Close closes lt. After calling Close, calls to Logf become no-ops. +func (lt *LogLineTracker) Close() { + lt.mu.Lock() + defer lt.mu.Unlock() + lt.closed = true +}