-
Notifications
You must be signed in to change notification settings - Fork 889
chore: Use contexts with timeout in coderd
tests
#3381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c352a07
chore: Use contexts with timeout in `coderd` tests
mafredri 4f7e32e
fix: Speed up TestPaginatedUsers by creating users concurrently
mafredri ae17114
fix: Bump timeout even more, add individual timeout for assert
mafredri d76d9ca
chore: Convert into table based test with subtests
mafredri 421e52d
chore: Add nolint
mafredri 0a7642c
chore: Speed up TestPaginatedTemplateVersions via errgroup
mafredri e3ad325
chore: Manually check template version to control timeout
mafredri 8f5213d
fix: Use testutil constants
mafredri 3774fb1
fix: Whoops
mafredri 98b89ba
chore: Increase assert pagination timeout
mafredri 52d480c
Merge branch 'main' into mafredri/coderd-test-timeouts
mafredri 0ac5fac
Merge branch 'main' into mafredri/coderd-test-timeouts
mafredri 1b99e0b
Merge branch 'main' into mafredri/coderd-test-timeouts
mafredri b7600aa
Merge branch 'main' into mafredri/coderd-test-timeouts
mafredri f770c21
Update coderd/templateversions_test.go
mafredri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
|
||
"github.com/coder/coder/coderd/coderdtest" | ||
"github.com/coder/coder/codersdk" | ||
"github.com/coder/coder/testutil" | ||
) | ||
|
||
func TestPostFiles(t *testing.T) { | ||
|
@@ -17,26 +18,38 @@ func TestPostFiles(t *testing.T) { | |
t.Parallel() | ||
client := coderdtest.New(t, nil) | ||
_ = coderdtest.CreateFirstUser(t, client) | ||
_, err := client.Upload(context.Background(), "bad", []byte{'a'}) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As much as possible, I tried to ensure contexts are initialized after test environment has been set up (e.g. post- coderd client, user creation etc). This ensures the timeout is applied only to the part being tested. The |
||
defer cancel() | ||
|
||
_, err := client.Upload(ctx, "bad", []byte{'a'}) | ||
require.Error(t, err) | ||
}) | ||
|
||
t.Run("Insert", func(t *testing.T) { | ||
t.Parallel() | ||
client := coderdtest.New(t, nil) | ||
_ = coderdtest.CreateFirstUser(t, client) | ||
_, err := client.Upload(context.Background(), codersdk.ContentTypeTar, make([]byte, 1024)) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) | ||
defer cancel() | ||
|
||
_, err := client.Upload(ctx, codersdk.ContentTypeTar, make([]byte, 1024)) | ||
require.NoError(t, err) | ||
}) | ||
|
||
t.Run("InsertAlreadyExists", func(t *testing.T) { | ||
t.Parallel() | ||
client := coderdtest.New(t, nil) | ||
_ = coderdtest.CreateFirstUser(t, client) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) | ||
defer cancel() | ||
|
||
data := make([]byte, 1024) | ||
_, err := client.Upload(context.Background(), codersdk.ContentTypeTar, data) | ||
_, err := client.Upload(ctx, codersdk.ContentTypeTar, data) | ||
require.NoError(t, err) | ||
_, err = client.Upload(context.Background(), codersdk.ContentTypeTar, data) | ||
_, err = client.Upload(ctx, codersdk.ContentTypeTar, data) | ||
require.NoError(t, err) | ||
}) | ||
} | ||
|
@@ -47,7 +60,11 @@ func TestDownload(t *testing.T) { | |
t.Parallel() | ||
client := coderdtest.New(t, nil) | ||
_ = coderdtest.CreateFirstUser(t, client) | ||
_, _, err := client.Download(context.Background(), "something") | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) | ||
defer cancel() | ||
|
||
_, _, err := client.Download(ctx, "something") | ||
var apiErr *codersdk.Error | ||
require.ErrorAs(t, err, &apiErr) | ||
require.Equal(t, http.StatusNotFound, apiErr.StatusCode()) | ||
|
@@ -57,9 +74,13 @@ func TestDownload(t *testing.T) { | |
t.Parallel() | ||
client := coderdtest.New(t, nil) | ||
_ = coderdtest.CreateFirstUser(t, client) | ||
resp, err := client.Upload(context.Background(), codersdk.ContentTypeTar, make([]byte, 1024)) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) | ||
defer cancel() | ||
|
||
resp, err := client.Upload(ctx, codersdk.ContentTypeTar, make([]byte, 1024)) | ||
require.NoError(t, err) | ||
data, contentType, err := client.Download(context.Background(), resp.Hash) | ||
data, contentType, err := client.Download(ctx, resp.Hash) | ||
require.NoError(t, err) | ||
require.Len(t, data, 1024) | ||
require.Equal(t, codersdk.ContentTypeTar, contentType) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.