mirror of
https://github.com/hanzo-fi/go-libs.git
synced 2026-10-30 20:53:44 +00:00
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package observefx_test
|
|
|
|
import (
|
|
"sync/atomic"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"go.opentelemetry.io/contrib/instrumentation/runtime"
|
|
"go.uber.org/fx"
|
|
"go.uber.org/fx/fxtest"
|
|
|
|
"github.com/hanzo-fi/go-libs/v5/pkg/fx/observefx"
|
|
"github.com/hanzo-fi/go-libs/v5/pkg/observe"
|
|
"github.com/hanzo-fi/go-libs/v5/pkg/observe/metrics"
|
|
)
|
|
|
|
func TestMetricsModuleProvidesRuntimeOptionsToRuntimeMetricsInvoke(t *testing.T) {
|
|
var runtimeOptionProvided atomic.Bool
|
|
|
|
app := fxtest.New(t,
|
|
observefx.ResourceModule(observe.Config{
|
|
ServiceName: "metrics-test",
|
|
}),
|
|
observefx.MetricsModule(metrics.ModuleConfig{
|
|
MinimumReadMemStatsInterval: time.Second,
|
|
}),
|
|
observefx.ProvideRuntimeMetricsOption(func() runtime.Option {
|
|
runtimeOptionProvided.Store(true)
|
|
return runtime.WithMinimumReadMemStatsInterval(100 * time.Millisecond)
|
|
}),
|
|
fx.NopLogger,
|
|
)
|
|
app.RequireStart()
|
|
defer app.RequireStop()
|
|
|
|
require.True(t, runtimeOptionProvided.Load())
|
|
}
|
|
|
|
func TestMetricsModuleDoesNotProvideZeroRuntimeMetricsInterval(t *testing.T) {
|
|
var runtimeOptionsCount int
|
|
|
|
app := fxtest.New(t,
|
|
observefx.ResourceModule(observe.Config{
|
|
ServiceName: "metrics-test",
|
|
}),
|
|
observefx.MetricsModule(metrics.ModuleConfig{}),
|
|
fx.Invoke(fx.Annotate(
|
|
func(options ...runtime.Option) {
|
|
runtimeOptionsCount = len(options)
|
|
},
|
|
fx.ParamTags(`group:"_metricsRuntimeOption"`),
|
|
)),
|
|
fx.NopLogger,
|
|
)
|
|
app.RequireStart()
|
|
defer app.RequireStop()
|
|
|
|
require.Zero(t, runtimeOptionsCount)
|
|
}
|