Skip to content

Commit

Permalink
Make TestInvokeReturningSecrets no longer flaky (#655)
Browse files Browse the repository at this point in the history
### 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.
  • Loading branch information
Zaid-Ajaj authored Oct 9, 2024
1 parent 7e561fd commit d3fd26c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/pulumiyaml/run_invoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d3fd26c

Please sign in to comment.