Skip to content

Commit 07d6f91

Browse files
committed
test(policies): drop timing-dependent rego timeout tests
The evaluation-bound tests relied on a hardcoded cross product outrunning a 200ms timeout, which is not a property CI hardware guarantees. Remove them along with their fixture, keeping the option-handling coverage. Assisted-by: Claude Code Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
1 parent 5bc6b1f commit 07d6f91

2 files changed

Lines changed: 0 additions & 89 deletions

File tree

‎pkg/policies/engine/rego/rego_test.go‎

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -898,65 +898,3 @@ func TestRego_ExecutionTimeoutOption(t *testing.T) {
898898
})
899899
}
900900
}
901-
902-
func TestRego_VerifyIsBoundedByExecutionTimeout(t *testing.T) {
903-
regoContent, err := os.ReadFile("testfiles/slow_evaluation.rego")
904-
require.NoError(t, err)
905-
906-
policy := &engine.Policy{Name: "slow evaluation", Source: regoContent}
907-
908-
testCases := []struct {
909-
name string
910-
// executionTimeout configured in the engine
911-
executionTimeout time.Duration
912-
// deadline carried by the caller context, if any
913-
callerTimeout time.Duration
914-
}{
915-
{
916-
name: "the engine timeout bounds an unbounded caller context",
917-
executionTimeout: 200 * time.Millisecond,
918-
},
919-
{
920-
name: "a shorter caller deadline is not extended by the engine timeout",
921-
executionTimeout: time.Hour,
922-
callerTimeout: 200 * time.Millisecond,
923-
},
924-
}
925-
926-
for _, tc := range testCases {
927-
t.Run(tc.name, func(t *testing.T) {
928-
ctx := context.Background()
929-
if tc.callerTimeout > 0 {
930-
var cancel context.CancelFunc
931-
ctx, cancel = context.WithTimeout(ctx, tc.callerTimeout)
932-
defer cancel()
933-
}
934-
935-
r := NewEngine(engine.WithExecutionTimeout(tc.executionTimeout))
936-
937-
start := time.Now()
938-
_, err := r.Verify(ctx, policy, []byte("{}"), nil)
939-
elapsed := time.Since(start)
940-
941-
require.Error(t, err)
942-
assert.ErrorIs(t, err, context.DeadlineExceeded)
943-
assert.Less(t, elapsed, 10*time.Second, "evaluation was not interrupted")
944-
})
945-
}
946-
}
947-
948-
func TestRego_MatchesEvaluationIsBoundedByExecutionTimeout(t *testing.T) {
949-
regoContent, err := os.ReadFile("testfiles/slow_evaluation.rego")
950-
require.NoError(t, err)
951-
952-
r := NewEngine(engine.WithExecutionTimeout(200 * time.Millisecond))
953-
policy := &engine.Policy{Name: "slow evaluation", Source: regoContent}
954-
955-
start := time.Now()
956-
_, err = r.MatchesEvaluation(context.Background(), policy, []string{"a violation"}, nil)
957-
elapsed := time.Since(start)
958-
959-
require.Error(t, err)
960-
assert.ErrorIs(t, err, context.DeadlineExceeded)
961-
assert.Less(t, elapsed, 10*time.Second, "evaluation was not interrupted")
962-
}

‎pkg/policies/engine/rego/testfiles/slow_evaluation.rego‎

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)