Skip to content

Commit

Permalink
feat(api): Allow for the repo test deadline to be configured.
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffFaer committed Apr 4, 2024
1 parent e5bf616 commit 3498cb8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion api/repotest/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ type Options struct {
ExtraListWorkUnitPrefixes []ListWorkUnitTestCase

Parallel bool

// The deadline to use for test cases.
// Defaults to 5s.
Deadline time.Duration
}

type ListWorkUnitTestCase struct {
Expand All @@ -37,6 +41,10 @@ type ListWorkUnitTestCase struct {
type repoCtor func(*testing.T) api.Repository

func RepoTests(t *testing.T, ctor func(context.Context, *testing.T, string) (api.Repository, error), opts Options) {
if opts.Deadline == 0 {
opts.Deadline = 5 * time.Second
}

for n, tc := range map[string]func(context.Context, *testing.T, repoCtor, Options){
"EmptyRepository": testEmptyRepository,
"New": testNew,
Expand All @@ -50,7 +58,7 @@ func RepoTests(t *testing.T, ctor func(context.Context, *testing.T, string) (api
if opts.Parallel {
t.Parallel()
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), opts.Deadline)
defer cancel()
ctor := func(t *testing.T) api.Repository {
repo, err := ctor(ctx, t, t.Name())
Expand Down

0 comments on commit 3498cb8

Please sign in to comment.