Skip to content

Commit 6d41edc

Browse files
committed
test: Handle Fitler flake with ctx errors
1 parent 17f692a commit 6d41edc

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

coderd/rbac/authz.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ func Filter[O Objecter](ctx context.Context, auth Authorizer, subject Subject, a
137137
err := auth.Authorize(ctx, subject, action, o.RBACObject())
138138
if err == nil {
139139
filtered = append(filtered, o)
140+
} else if ctx.Err() != nil {
141+
// Exit early if the error comes from the context
142+
return nil, ctx.Err()
140143
}
141144
}
142145
return filtered, nil
@@ -155,6 +158,9 @@ func Filter[O Objecter](ctx context.Context, auth Authorizer, subject Subject, a
155158
err := prepared.Authorize(ctx, rbacObj)
156159
if err == nil {
157160
filtered = append(filtered, object)
161+
} else if ctx.Err() != nil {
162+
// Exit early if the error comes from the context
163+
return nil, ctx.Err()
158164
}
159165
}
160166

coderd/rbac/authz_internal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func TestFilter(t *testing.T) {
170170
localObjects := make([]fakeObject, len(objects))
171171
copy(localObjects, objects)
172172

173-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
173+
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
174174
defer cancel()
175175
auth := NewAuthorizer(prometheus.NewRegistry())
176176

0 commit comments

Comments
 (0)