Skip to content

Commit

Permalink
added tests for ignoring context errors
Browse files Browse the repository at this point in the history
  • Loading branch information
prasad-shirodkar committed Apr 17, 2024
1 parent 3dae347 commit 48d3eb8
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion exporters/stdout/stdoutmetric/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,36 @@ func testCtxErrHonored(factory func(*testing.T) func(context.Context) error) fun
}
}

func TestExporterHonorsContextErrors(t *testing.T) {
func testCtxErrIgnored(factory func(*testing.T) func(context.Context) error) func(t *testing.T) {
return func(t *testing.T) {
t.Helper()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)

t.Run("DeadlineExceeded Ignored", func(t *testing.T) {
innerCtx, innerCancel := context.WithTimeout(ctx, time.Nanosecond)
t.Cleanup(innerCancel)

f := factory(t)
assert.NoError(t, f(innerCtx))
})

t.Run("Canceled Ignored", func(t *testing.T) {
innerCtx, innerCancel := context.WithCancel(ctx)
innerCancel()

f := factory(t)
assert.NoError(t, f(innerCtx))
})

t.Run("NoError", func(t *testing.T) {
f := factory(t)
assert.NoError(t, f(ctx))
})
}
}

func TestExporterExportHonorsContextErrors(t *testing.T) {
t.Run("Export", testCtxErrHonored(func(t *testing.T) func(context.Context) error {
exp, err := stdoutmetric.New(testEncoderOption())
require.NoError(t, err)
Expand All @@ -65,6 +94,22 @@ func TestExporterHonorsContextErrors(t *testing.T) {
}))
}

func TestExporterForceFlushIgnoresContextErrors(t *testing.T) {
t.Run("ForceFlush", testCtxErrIgnored(func(t *testing.T) func(context.Context) error {
exp, err := stdoutmetric.New(testEncoderOption())
require.NoError(t, err)
return exp.ForceFlush
}))
}

func TestExporterShutdownIgnoresContextErrors(t *testing.T) {
t.Run("Shutdown", testCtxErrIgnored(func(t *testing.T) func(context.Context) error {
exp, err := stdoutmetric.New(testEncoderOption())
require.NoError(t, err)
return exp.Shutdown
}))
}

func TestExporterShutdown(t *testing.T) {
exporter, err := stdoutmetric.New(testEncoderOption())
assert.NoError(t, err)
Expand Down

0 comments on commit 48d3eb8

Please sign in to comment.