diff --git a/logging/logging_test.go b/logging/logging_test.go index d3e15b155d7f..1f07c7ba7f83 100644 --- a/logging/logging_test.go +++ b/logging/logging_test.go @@ -1420,7 +1420,7 @@ func TestInstrumentationWithRedirect(t *testing.T) { entry := &logging.Entry{Severity: logging.Info, Payload: "test string"} buffer := &strings.Builder{} logger := client.Logger("test-redirect-output", logging.RedirectAsJSON(buffer)) - onceBackup := internal.InstrumentOnce + onceBackup, timeBackup := internal.InstrumentOnce, logging.SetNow(testNow) internal.InstrumentOnce = new(sync.Once) for i := range want { buffer.Reset() @@ -1433,6 +1433,7 @@ func TestInstrumentationWithRedirect(t *testing.T) { t.Errorf("got(%v), want(%v)", got, want[i]) } } + logging.SetNow(timeBackup) internal.InstrumentOnce = onceBackup } diff --git a/logging/logging_unexported_test.go b/logging/logging_unexported_test.go index 55f3f4d0e201..eb0b91c85cd4 100644 --- a/logging/logging_unexported_test.go +++ b/logging/logging_unexported_test.go @@ -351,6 +351,7 @@ func TestMonitoredResource(t *testing.T) { } // Used by the tests in logging_test. -func SetNow(f func() time.Time) { - now = f +func SetNow(f func() time.Time) func() time.Time { + now, f = f, now + return f }