Skip to content

Commit d595842

Browse files
committed
add context with timeout to observability tests
1 parent c47300f commit d595842

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

gcp/observability/observability_test.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ func (s) TestRefuseStartWithInvalidPatterns(t *testing.T) {
184184
envconfig.ObservabilityConfigFile = oldObservabilityConfigFile
185185
}()
186186
// If there is at least one invalid pattern, which should not be silently tolerated.
187-
if err := Start(context.Background()); err == nil {
187+
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
188+
defer cancel()
189+
if err := Start(ctx); err == nil {
188190
t.Fatalf("Invalid patterns not triggering error")
189191
}
190192
}
@@ -220,7 +222,9 @@ func (s) TestRefuseStartWithExcludeAndWildCardAll(t *testing.T) {
220222
envconfig.ObservabilityConfigFile = oldObservabilityConfigFile
221223
}()
222224
// If there is at least one invalid pattern, which should not be silently tolerated.
223-
if err := Start(context.Background()); err == nil {
225+
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
226+
defer cancel()
227+
if err := Start(ctx); err == nil {
224228
t.Fatalf("Invalid patterns not triggering error")
225229
}
226230
}
@@ -316,7 +320,9 @@ func (s) TestBothConfigEnvVarsSet(t *testing.T) {
316320
defer func() {
317321
envconfig.ObservabilityConfig = oldObservabilityConfig
318322
}()
319-
if err := Start(context.Background()); err == nil {
323+
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
324+
defer cancel()
325+
if err := Start(ctx); err == nil {
320326
t.Fatalf("Invalid patterns not triggering error")
321327
}
322328
}
@@ -331,7 +337,9 @@ func (s) TestErrInFileSystemEnvVar(t *testing.T) {
331337
defer func() {
332338
envconfig.ObservabilityConfigFile = oldObservabilityConfigFile
333339
}()
334-
if err := Start(context.Background()); err == nil {
340+
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
341+
defer cancel()
342+
if err := Start(ctx); err == nil {
335343
t.Fatalf("Invalid file system path not triggering error")
336344
}
337345
}
@@ -346,7 +354,9 @@ func (s) TestNoEnvSet(t *testing.T) {
346354
envconfig.ObservabilityConfigFile = oldObservabilityConfigFile
347355
}()
348356
// If there is no observability config set at all, the Start should return an error.
349-
if err := Start(context.Background()); err == nil {
357+
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
358+
defer cancel()
359+
if err := Start(ctx); err == nil {
350360
t.Fatalf("Invalid patterns not triggering error")
351361
}
352362
}
@@ -540,7 +550,9 @@ func (s) TestStartErrorsThenEnd(t *testing.T) {
540550
envconfig.ObservabilityConfig = oldObservabilityConfig
541551
envconfig.ObservabilityConfigFile = oldObservabilityConfigFile
542552
}()
543-
if err := Start(context.Background()); err == nil {
553+
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
554+
defer cancel()
555+
if err := Start(ctx); err == nil {
544556
t.Fatalf("Invalid patterns not triggering error")
545557
}
546558
End()

0 commit comments

Comments
 (0)