promql.Engine.Close: No-op if nil (#14861)
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
parent
9f57f14d6c
commit
db5e48dc33
|
@ -435,6 +435,10 @@ func NewEngine(opts EngineOpts) *Engine {
|
||||||
|
|
||||||
// Close closes ng.
|
// Close closes ng.
|
||||||
func (ng *Engine) Close() error {
|
func (ng *Engine) Close() error {
|
||||||
|
if ng == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if ng.activeQueryTracker != nil {
|
if ng.activeQueryTracker != nil {
|
||||||
return ng.activeQueryTracker.Close()
|
return ng.activeQueryTracker.Close()
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
func TestInstantQueryWithRangeVectorSelector(t *testing.T) {
|
||||||
engine := newTestEngine(t)
|
engine := newTestEngine(t)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue