Skip to content

Commit ef7d357

Browse files
authored
fix: Move timeout ctx closer to use in tests, increase timeout (coder#3109)
Some contexts were moved closer to use so that test setup doesn't affect timeout. And timeout was increased for some others to avoid flakyness due to slow test runners.
1 parent e874d53 commit ef7d357

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

cli/list_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ func TestList(t *testing.T) {
1616
t.Parallel()
1717
t.Run("Single", func(t *testing.T) {
1818
t.Parallel()
19-
ctx, cancelFunc := context.WithTimeout(context.Background(), 5*time.Second)
20-
defer cancelFunc()
2119
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
2220
user := coderdtest.CreateFirstUser(t, client)
2321
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
@@ -30,6 +28,9 @@ func TestList(t *testing.T) {
3028
pty := ptytest.New(t)
3129
cmd.SetIn(pty.Input())
3230
cmd.SetOut(pty.Output())
31+
32+
ctx, cancelFunc := context.WithTimeout(context.Background(), 5*time.Second)
33+
defer cancelFunc()
3334
done := make(chan any)
3435
go func() {
3536
errC := cmd.ExecuteContext(ctx)

coderd/provisionerjobs_internal_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ func TestProvisionerJobLogs_Unit(t *testing.T) {
2727
t.Parallel()
2828

2929
t.Run("QueryPubSubDupes", func(t *testing.T) {
30-
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
31-
t.Cleanup(cancel)
3230
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
3331
// mDB := mocks.NewStore(t)
3432
fDB := databasefake.New()
@@ -65,6 +63,9 @@ func TestProvisionerJobLogs_Unit(t *testing.T) {
6563
{ID: uuid.New(), JobID: jobID, Stage: "Stage3"},
6664
}
6765

66+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
67+
defer cancel()
68+
6869
// wow there are a lot of DB rows we touch...
6970
_, err = fDB.InsertAPIKey(ctx, database.InsertAPIKeyParams{
7071
ID: keyID,

site/site_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestCaching(t *testing.T) {
4848
defer srv.Close()
4949

5050
// Create a context
51-
ctx, cancelFunc := context.WithTimeout(context.Background(), 1*time.Second)
51+
ctx, cancelFunc := context.WithTimeout(context.Background(), 5*time.Second)
5252
defer cancelFunc()
5353

5454
testCases := []struct {
@@ -108,7 +108,7 @@ func TestServingFiles(t *testing.T) {
108108
defer srv.Close()
109109

110110
// Create a context
111-
ctx, cancelFunc := context.WithTimeout(context.Background(), 1*time.Second)
111+
ctx, cancelFunc := context.WithTimeout(context.Background(), 5*time.Second)
112112
defer cancelFunc()
113113

114114
testCases := []struct {
@@ -337,7 +337,7 @@ func TestServingBin(t *testing.T) {
337337
defer srv.Close()
338338

339339
// Create a context
340-
ctx, cancelFunc := context.WithTimeout(context.Background(), 1*time.Second)
340+
ctx, cancelFunc := context.WithTimeout(context.Background(), 5*time.Second)
341341
defer cancelFunc()
342342

343343
for _, tr := range tt.reqs {

0 commit comments

Comments
 (0)