promql.Engine.Close: No-op if nil (#14861)

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Arve Knudsen 2024-09-08 14:39:13 +02:00 committed by GitHub
parent 9f57f14d6c
commit db5e48dc33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 0 deletions

View file

@ -435,6 +435,10 @@ func NewEngine(opts EngineOpts) *Engine {
// Close closes ng.
func (ng *Engine) Close() error {
if ng == nil {
return nil
}
if ng.activeQueryTracker != nil {
return ng.activeQueryTracker.Close()
}

View file

@ -3019,6 +3019,29 @@ func TestEngineOptsValidation(t *testing.T) {
}
}
func TestEngine_Close(t *testing.T) {
t.Run("nil engine", func(t *testing.T) {
var ng *promql.Engine
require.NoError(t, ng.Close())
})
t.Run("non-nil engine", func(t *testing.T) {
ng := promql.NewEngine(promql.EngineOpts{
Logger: nil,
Reg: nil,
MaxSamples: 0,
Timeout: 100 * time.Second,
NoStepSubqueryIntervalFn: nil,
EnableAtModifier: true,
EnableNegativeOffset: true,
EnablePerStepStats: false,
LookbackDelta: 0,
EnableDelayedNameRemoval: true,
})
require.NoError(t, ng.Close())
})
}
func TestInstantQueryWithRangeVectorSelector(t *testing.T) {
engine := newTestEngine(t)