From d3fd26c92b4c0ec1161698012d74a4e5f951b065 Mon Sep 17 00:00:00 2001 From: Zaid Ajaj Date: Thu, 10 Oct 2024 01:10:02 +0200 Subject: [PATCH] Make TestInvokeReturningSecrets no longer flaky (#655) ### Description Fixes #653. The problem was that sometimes the test finishes executing before the apply function finished running and it became a race. Fixed using channels that signal when the apply function is done and waiting for it. If it takes longer than 2 seconds, it times out. --- pkg/pulumiyaml/run_invoke_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/pulumiyaml/run_invoke_test.go b/pkg/pulumiyaml/run_invoke_test.go index 2c885e22..73b92a27 100644 --- a/pkg/pulumiyaml/run_invoke_test.go +++ b/pkg/pulumiyaml/run_invoke_test.go @@ -6,6 +6,7 @@ import ( "fmt" "strings" "testing" + "time" "github.com/pulumi/pulumi-yaml/pkg/pulumiyaml/ast" "github.com/pulumi/pulumi-yaml/pkg/pulumiyaml/syntax" @@ -232,17 +233,24 @@ outputs: tmpl := yamlTemplate(t, strings.TrimSpace(text)) var innerValue string + done := make(chan bool) diags := testInvokeDiags(t, tmpl, func(r *Runner) { cipher, ok := r.variables["cipher"].(pulumi.AnyOutput) assert.True(t, ok) assert.NotNil(t, cipher) cipher.ApplyT(func(v interface{}) interface{} { innerValue = v.(string) + done <- true return v }) }) - requireNoErrors(t, tmpl, diags) - assert.Equal(t, "super-secret", innerValue) + select { + case <-done: + requireNoErrors(t, tmpl, diags) + assert.Equal(t, "super-secret", innerValue) + case <-time.After(2 * time.Second): + t.Fatal("Timed out waiting for the secret to be resolved") + } } func testInvokeDiags(t *testing.T, template *ast.TemplateDecl, callback func(*Runner)) syntax.Diagnostics {