From 06918f4c69ee9d694702734b28dce03b2cf3bfeb Mon Sep 17 00:00:00 2001 From: Tara Gu Date: Fri, 20 Sep 2019 13:42:06 -0400 Subject: [PATCH] Remove caching in test logger setup (#661) * Remove caching in test logger setup * Revert "Remove caching in test logger setup" This reverts commit e3c5349e3cb8a03e4a43bd3ebbdf0b102a4c3561. * Don't create new logger in SetupFakeContextWithCancel * Revert "Don't create new logger in SetupFakeContextWithCancel" This reverts commit 2d57ccf0285bb0a0bc7c0dc5a1f959a2c3823b55. * Remove test logger cache, and leave an empty shell for ClearAll() --- logging/testing/util.go | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/logging/testing/util.go b/logging/testing/util.go index 29daf9934..6773a10fe 100644 --- a/logging/testing/util.go +++ b/logging/testing/util.go @@ -18,7 +18,6 @@ package testing import ( "context" - "sync" "testing" "go.uber.org/zap" @@ -27,40 +26,19 @@ import ( "knative.dev/pkg/logging" ) -var ( - loggers = make(map[string]*zap.SugaredLogger) - m sync.Mutex -) - // TestLogger gets a logger to use in unit and end to end tests func TestLogger(t *testing.T) *zap.SugaredLogger { - m.Lock() - defer m.Unlock() - - logger, ok := loggers[t.Name()] - - if ok { - return logger - } - opts := zaptest.WrapOptions( zap.AddCaller(), zap.Development(), ) - logger = zaptest.NewLogger(t, opts).Sugar().Named(t.Name()) - loggers[t.Name()] = logger - - return logger + return zaptest.NewLogger(t, opts).Sugar() } // ClearAll removes all the testing loggers. -// `go test -count=X` executes runs in the same process, thus the map -// persists between the runs, but the `t` will no longer be valid and will -// cause a panic deep inside testing code. -func ClearAll() { - loggers = make(map[string]*zap.SugaredLogger) -} +// TODO(taragu) remove this after removing all ClearAll() calls from serving and eventing +func ClearAll() {} // TestContextWithLogger returns a context with a logger to be used in tests func TestContextWithLogger(t *testing.T) context.Context {