MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / TestConcurrentVerifyStatement

Function TestConcurrentVerifyStatement

pkg/policies/concurrency_test.go:36–80  ·  view source on GitHub ↗

TestConcurrentVerifyStatement runs VerifyStatement from multiple goroutines to exercise errgroup parallelism and catch race conditions. Run with: go test -race -count=1 -run TestConcurrentVerifyStatement ./pkg/policies/...

(t *testing.T)

Source from the content-addressed store, hash-verified

34// to exercise errgroup parallelism and catch race conditions.
35// Run with: go test -race -count=1 -run TestConcurrentVerifyStatement ./pkg/policies/...
36func TestConcurrentVerifyStatement(t *testing.T) {
37 logger := zerolog.Nop()
38
39 schema := &v12.CraftingSchema{
40 Policies: &v12.Policies{
41 Attestation: []*v12.PolicyAttachment{
42 {Policy: &v12.PolicyAttachment_Ref{Ref: "file://testdata/workflow.yaml"}},
43 {Policy: &v12.PolicyAttachment_Ref{Ref: "file://testdata/materials.yaml"}},
44 },
45 },
46 }
47
48 statement := loadStatementForTest(t, "testdata/statement.json")
49
50 pv := NewPolicyVerifier(schema.GetPolicies(), nil, &logger)
51
52 // Run multiple VerifyStatement calls concurrently
53 const goroutines = 10
54 var wg sync.WaitGroup
55 errs := make([]error, goroutines)
56 results := make([][]*v1.PolicyEvaluation, goroutines)
57
58 for i := range goroutines {
59 wg.Add(1)
60 go func() {
61 defer wg.Done()
62 res, err := pv.VerifyStatement(context.Background(), statement)
63 errs[i] = err
64 results[i] = res
65 }()
66 }
67
68 wg.Wait()
69
70 // All calls should succeed
71 for i := range goroutines {
72 assert.NoError(t, errs[i], "goroutine %d failed", i)
73 }
74
75 // All calls should return the same number of evaluations
76 for i := 1; i < goroutines; i++ {
77 assert.Equal(t, len(results[0]), len(results[i]),
78 "goroutine %d returned different number of evaluations", i)
79 }
80}
81
82// TestConcurrentVerifyMaterial runs VerifyMaterial from multiple goroutines.
83func TestConcurrentVerifyMaterial(t *testing.T) {

Callers

nothing calls this directly

Calls 5

GetPoliciesMethod · 0.95
VerifyStatementMethod · 0.95
loadStatementForTestFunction · 0.85
NewPolicyVerifierFunction · 0.85
AddMethod · 0.45

Tested by

no test coverage detected