Skip to content

Commit

Permalink
test(logging): fix TestInstrumentationIngestion in integration env (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
minherz authored Jul 1, 2022
1 parent c0a0c20 commit df178f8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion logging/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -1433,6 +1433,7 @@ func TestInstrumentationWithRedirect(t *testing.T) {
t.Errorf("got(%v), want(%v)", got, want[i])
}
}
logging.SetNow(timeBackup)
internal.InstrumentOnce = onceBackup
}

Expand Down
5 changes: 3 additions & 2 deletions logging/logging_unexported_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit df178f8

Please sign in to comment.