From 94ca9bc6135936599bde40ffec3675801d2005e5 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Fri, 10 Nov 2023 16:01:08 -0800 Subject: [PATCH] stackeval: testEvaluator arranges for its result to be cleaned up Some operations against an "evaluator" (type Main) register cleanup actions that need to be run once the evaluation has completed. To avoid leaking resources while we're running tests we'll arrange for any test that uses the "testEvaluator" helper to automatically run the cleanup actions on the returned evaluator once the test is complete. At the time of this commit the only possible cleanup action is terminating any provider pluginc client processes that might be running, and none of our tests are actually doing that so this doesn't really change anything, but it's here to avoid problems if we add additional cleanup actions in future, or if any tests start actually using child plugin processes. --- .../stacks/stackruntime/internal/stackeval/testing_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/stacks/stackruntime/internal/stackeval/testing_test.go b/internal/stacks/stackruntime/internal/stackeval/testing_test.go index 568d819eeb..b391419acd 100644 --- a/internal/stacks/stackruntime/internal/stackeval/testing_test.go +++ b/internal/stacks/stackruntime/internal/stackeval/testing_test.go @@ -109,11 +109,15 @@ func testEvaluator(t *testing.T, opts testEvaluatorOpts) *Main { } } - return NewForInspecting(opts.Config, opts.State, InspectOpts{ + main := NewForInspecting(opts.Config, opts.State, InspectOpts{ InputVariableValues: inputVals, ProviderFactories: opts.ProviderFactories, TestOnlyGlobals: opts.TestOnlyGlobals, }) + t.Cleanup(func() { + main.DoCleanup(context.Background()) + }) + return main } type testEvaluatorOpts struct {