@@ -73,8 +73,7 @@ func TestCreateWorkspace(t *testing.T) {
73
73
74
74
other , _ := coderdtest .CreateAnotherUser (t , client , first .OrganizationID , rbac .RoleMember (), rbac .RoleOwner ())
75
75
76
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
77
- defer cancel ()
76
+ ctx := testutil .Context (t , testutil .WaitLong )
78
77
79
78
org , err := other .CreateOrganization (ctx , codersdk.CreateOrganizationRequest {
80
79
Name : "another" ,
@@ -83,6 +82,8 @@ func TestCreateWorkspace(t *testing.T) {
83
82
version := coderdtest .CreateTemplateVersion (t , other , org .ID , nil )
84
83
template := coderdtest .CreateTemplate (t , other , org .ID , version .ID )
85
84
85
+ ctx = testutil .Context (t , testutil .WaitLong ) // Reset the context to avoid timeouts.
86
+
86
87
_ , err = client .CreateWorkspace (ctx , first .OrganizationID , codersdk .Me , codersdk.CreateWorkspaceRequest {
87
88
TemplateID : template .ID ,
88
89
Name : "workspace" ,
@@ -108,8 +109,7 @@ func TestCreateWorkspace(t *testing.T) {
108
109
version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
109
110
template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
110
111
111
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
112
- defer cancel ()
112
+ ctx := testutil .Context (t , testutil .WaitLong )
113
113
114
114
acl , err := templateAdminClient .TemplateACL (ctx , template .ID )
115
115
require .NoError (t , err )
@@ -163,8 +163,7 @@ func TestCreateWorkspace(t *testing.T) {
163
163
coderdtest .AwaitTemplateVersionJobCompleted (t , templateAdmin , version .ID )
164
164
template := coderdtest .CreateTemplate (t , templateAdmin , owner .OrganizationID , version .ID )
165
165
166
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
167
- defer cancel ()
166
+ ctx := testutil .Context (t , testutil .WaitLong )
168
167
169
168
// Remove everyone access
170
169
err := templateAdmin .UpdateTemplateACL (ctx , template .ID , codersdk.UpdateTemplateACL {
@@ -213,8 +212,7 @@ func TestCreateUserWorkspace(t *testing.T) {
213
212
214
213
other , _ := coderdtest .CreateAnotherUser (t , client , first .OrganizationID , rbac .RoleMember (), rbac .RoleOwner ())
215
214
216
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
217
- defer cancel ()
215
+ ctx := testutil .Context (t , testutil .WaitLong )
218
216
219
217
org , err := other .CreateOrganization (ctx , codersdk.CreateOrganizationRequest {
220
218
Name : "another" ,
@@ -223,6 +221,8 @@ func TestCreateUserWorkspace(t *testing.T) {
223
221
version := coderdtest .CreateTemplateVersion (t , other , org .ID , nil )
224
222
template := coderdtest .CreateTemplate (t , other , org .ID , version .ID )
225
223
224
+ ctx = testutil .Context (t , testutil .WaitLong ) // Reset the context to avoid timeouts.
225
+
226
226
_ , err = client .CreateUserWorkspace (ctx , codersdk .Me , codersdk.CreateWorkspaceRequest {
227
227
TemplateID : template .ID ,
228
228
Name : "workspace" ,
@@ -248,8 +248,7 @@ func TestCreateUserWorkspace(t *testing.T) {
248
248
version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
249
249
template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
250
250
251
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
252
- defer cancel ()
251
+ ctx := testutil .Context (t , testutil .WaitLong )
253
252
254
253
acl , err := templateAdminClient .TemplateACL (ctx , template .ID )
255
254
require .NoError (t , err )
@@ -431,7 +430,6 @@ func TestWorkspaceAutobuild(t *testing.T) {
431
430
t .Parallel ()
432
431
433
432
var (
434
- ctx = testutil .Context (t , testutil .WaitMedium )
435
433
ticker = make (chan time.Time )
436
434
statCh = make (chan autobuild.Stats )
437
435
inactiveTTL = time .Minute
@@ -492,6 +490,8 @@ func TestWorkspaceAutobuild(t *testing.T) {
492
490
require .Equal (t , database .AuditActionWrite , alog .Action )
493
491
require .Equal (t , workspace .Name , alog .ResourceTarget )
494
492
493
+ ctx := testutil .Context (t , testutil .WaitMedium )
494
+
495
495
dormantLastUsedAt := ws .LastUsedAt
496
496
// nolint:gocritic // this test is not testing RBAC.
497
497
err := client .UpdateWorkspaceDormancy (ctx , ws .ID , codersdk.UpdateWorkspaceDormancy {Dormant : false })
@@ -861,7 +861,6 @@ func TestWorkspaceAutobuild(t *testing.T) {
861
861
t .Parallel ()
862
862
863
863
var (
864
- ctx = testutil .Context (t , testutil .WaitMedium )
865
864
tickCh = make (chan time.Time )
866
865
statsCh = make (chan autobuild.Stats )
867
866
inactiveTTL = time .Minute
@@ -909,6 +908,8 @@ func TestWorkspaceAutobuild(t *testing.T) {
909
908
ws = coderdtest .MustWorkspace (t , client , ws .ID )
910
909
coderdtest .AwaitWorkspaceBuildJobCompleted (t , client , ws .LatestBuild .ID )
911
910
911
+ ctx := testutil .Context (t , testutil .WaitMedium )
912
+
912
913
// Now that we've validated that the workspace is eligible for autostart
913
914
// lets cause it to become dormant.
914
915
_ , err = client .UpdateTemplateMeta (ctx , template .ID , codersdk.UpdateTemplateMeta {
@@ -944,7 +945,6 @@ func TestWorkspaceAutobuild(t *testing.T) {
944
945
ticker = make (chan time.Time )
945
946
statCh = make (chan autobuild.Stats )
946
947
transitionTTL = time .Minute
947
- ctx = testutil .Context (t , testutil .WaitMedium )
948
948
)
949
949
950
950
logger := slogtest .Make (t , & slogtest.Options {IgnoreErrors : true }).Leveled (slog .LevelDebug )
@@ -984,6 +984,8 @@ func TestWorkspaceAutobuild(t *testing.T) {
984
984
})
985
985
coderdtest .AwaitTemplateVersionJobCompleted (t , client , version .ID )
986
986
987
+ ctx := testutil .Context (t , testutil .WaitMedium )
988
+
987
989
// Try to delete the workspace. This simulates a "failed" autodelete.
988
990
build , err := templateAdmin .CreateWorkspaceBuild (ctx , ws .ID , codersdk.CreateWorkspaceBuildRequest {
989
991
Transition : codersdk .WorkspaceTransitionDelete ,
@@ -994,6 +996,8 @@ func TestWorkspaceAutobuild(t *testing.T) {
994
996
build = coderdtest .AwaitWorkspaceBuildJobCompleted (t , client , build .ID )
995
997
require .NotEmpty (t , build .Job .Error )
996
998
999
+ ctx = testutil .Context (t , testutil .WaitLong ) // Reset the context to avoid timeouts.
1000
+
997
1001
// Update our workspace to be dormant so that it qualifies for auto-deletion.
998
1002
err = templateAdmin .UpdateWorkspaceDormancy (ctx , ws .ID , codersdk.UpdateWorkspaceDormancy {
999
1003
Dormant : true ,
@@ -1030,7 +1034,6 @@ func TestWorkspaceAutobuild(t *testing.T) {
1030
1034
var (
1031
1035
tickCh = make (chan time.Time )
1032
1036
statsCh = make (chan autobuild.Stats )
1033
- ctx = testutil .Context (t , testutil .WaitMedium )
1034
1037
)
1035
1038
1036
1039
logger := slogtest .Make (t , & slogtest.Options {IgnoreErrors : true }).Leveled (slog .LevelDebug )
@@ -1070,6 +1073,8 @@ func TestWorkspaceAutobuild(t *testing.T) {
1070
1073
})
1071
1074
coderdtest .AwaitTemplateVersionJobCompleted (t , client , version2 .ID )
1072
1075
1076
+ ctx := testutil .Context (t , testutil .WaitMedium )
1077
+
1073
1078
// Make sure to promote it.
1074
1079
err = client .UpdateActiveTemplateVersion (ctx , template .ID , codersdk.UpdateActiveTemplateVersion {
1075
1080
ID : version2 .ID ,
@@ -1089,6 +1094,8 @@ func TestWorkspaceAutobuild(t *testing.T) {
1089
1094
firstBuild := coderdtest .AwaitWorkspaceBuildJobCompleted (t , client , started .LatestBuild .ID )
1090
1095
require .Equal (t , version1 .ID , firstBuild .TemplateVersionID )
1091
1096
1097
+ ctx = testutil .Context (t , testutil .WaitMedium ) // Reset the context after workspace operations.
1098
+
1092
1099
// Update the template to require the promoted version.
1093
1100
_ , err = client .UpdateTemplateMeta (ctx , template .ID , codersdk.UpdateTemplateMeta {
1094
1101
RequireActiveVersion : true ,
@@ -1538,9 +1545,6 @@ func TestWorkspaceTagsTerraform(t *testing.T) {
1538
1545
} {
1539
1546
tc := tc
1540
1547
t .Run (tc .name , func (t * testing.T ) {
1541
- // This can take a while, so set a relatively long timeout.
1542
- ctx := testutil .Context (t , 2 * testutil .WaitSuperLong )
1543
-
1544
1548
client , owner := coderdenttest .New (t , & coderdenttest.Options {
1545
1549
Options : & coderdtest.Options {
1546
1550
// We intentionally do not run a built-in provisioner daemon here.
@@ -1557,6 +1561,9 @@ func TestWorkspaceTagsTerraform(t *testing.T) {
1557
1561
1558
1562
_ = coderdenttest .NewExternalProvisionerDaemonTerraform (t , client , owner .OrganizationID , tc .provisionerTags )
1559
1563
1564
+ // This can take a while, so set a relatively long timeout.
1565
+ ctx := testutil .Context (t , 2 * testutil .WaitSuperLong )
1566
+
1560
1567
// Creating a template as a template admin must succeed
1561
1568
templateFiles := map [string ]string {"main.tf" : fmt .Sprintf (mainTfTemplate , tc .tfWorkspaceTags )}
1562
1569
tarBytes := testutil .CreateTar (t , templateFiles )
@@ -1595,13 +1602,11 @@ func downloadProviders(t *testing.T, providersTf string) string {
1595
1602
t .Helper ()
1596
1603
// We firstly write a Terraform CLI config file to a temporary directory:
1597
1604
var (
1598
- ctx , cancel = context .WithTimeout (context .Background (), testutil .WaitLong )
1599
1605
tempDir = t .TempDir ()
1600
1606
cacheDir = filepath .Join (tempDir , ".cache" )
1601
1607
providersTfPath = filepath .Join (tempDir , "providers.tf" )
1602
1608
cliConfigPath = filepath .Join (tempDir , "local.tfrc" )
1603
1609
)
1604
- defer cancel ()
1605
1610
1606
1611
// Write files to disk
1607
1612
require .NoError (t , os .MkdirAll (cacheDir , os .ModePerm | os .ModeDir ))
@@ -1619,6 +1624,8 @@ func downloadProviders(t *testing.T, providersTf string) string {
1619
1624
err := os .WriteFile (cliConfigPath , []byte (fmt .Sprintf (cliConfigTemplate , cacheDir )), os .ModePerm ) // nolint:gosec
1620
1625
require .NoError (t , err , "failed to write %s" , cliConfigPath )
1621
1626
1627
+ ctx := testutil .Context (t , testutil .WaitLong )
1628
+
1622
1629
// Run terraform providers mirror to mirror required providers to cacheDir
1623
1630
cmd := exec .CommandContext (ctx , "terraform" , "providers" , "mirror" , cacheDir )
1624
1631
cmd .Env = os .Environ () // without this terraform may complain about path
@@ -1702,7 +1709,6 @@ func TestWorkspacesFiltering(t *testing.T) {
1702
1709
t .Run ("Dormant" , func (t * testing.T ) {
1703
1710
t .Parallel ()
1704
1711
1705
- ctx := testutil .Context (t , testutil .WaitMedium )
1706
1712
logger := slogtest .Make (t , & slogtest.Options {IgnoreErrors : true }).Leveled (slog .LevelDebug )
1707
1713
client , db , owner := coderdenttest .NewWithDatabase (t , & coderdenttest.Options {
1708
1714
Options : & coderdtest.Options {
@@ -1736,6 +1742,8 @@ func TestWorkspacesFiltering(t *testing.T) {
1736
1742
TemplateID : resp .Template .ID ,
1737
1743
}).Do ().Workspace
1738
1744
1745
+ ctx := testutil .Context (t , testutil .WaitMedium )
1746
+
1739
1747
err := templateAdminClient .UpdateWorkspaceDormancy (ctx , dormantWS1 .ID , codersdk.UpdateWorkspaceDormancy {Dormant : true })
1740
1748
require .NoError (t , err )
1741
1749
@@ -2046,16 +2054,16 @@ func TestWorkspaceByOwnerAndName(t *testing.T) {
2046
2054
t .Run ("No Matching Provisioner" , func (t * testing.T ) {
2047
2055
t .Parallel ()
2048
2056
2049
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
2050
- defer cancel ()
2051
-
2052
2057
client , db , userResponse := coderdenttest .NewWithDatabase (t , & coderdenttest.Options {
2053
2058
LicenseOptions : & coderdenttest.LicenseOptions {
2054
2059
Features : license.Features {
2055
2060
codersdk .FeatureExternalProvisionerDaemons : 1 ,
2056
2061
},
2057
2062
},
2058
2063
})
2064
+
2065
+ ctx := testutil .Context (t , testutil .WaitLong )
2066
+
2059
2067
userSubject , _ , err := httpmw .UserRBACSubject (ctx , db , userResponse .UserID , rbac .ExpandableScope (rbac .ScopeAll ))
2060
2068
require .NoError (t , err )
2061
2069
user , err := client .User (ctx , userSubject .ID )
@@ -2070,6 +2078,8 @@ func TestWorkspaceByOwnerAndName(t *testing.T) {
2070
2078
coderdtest .AwaitTemplateVersionJobCompleted (t , client , version .ID )
2071
2079
template := coderdtest .CreateTemplate (t , client , userResponse .OrganizationID , version .ID )
2072
2080
2081
+ ctx = testutil .Context (t , testutil .WaitLong ) // Reset the context to avoid timeouts.
2082
+
2073
2083
// nolint:gocritic // unit testing
2074
2084
daemons , err := db .GetProvisionerDaemons (dbauthz .AsSystemRestricted (ctx ))
2075
2085
require .NoError (t , err )
@@ -2121,16 +2131,16 @@ func TestWorkspaceByOwnerAndName(t *testing.T) {
2121
2131
t .Run ("Unavailable Provisioner" , func (t * testing.T ) {
2122
2132
t .Parallel ()
2123
2133
2124
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
2125
- defer cancel ()
2126
-
2127
2134
client , db , userResponse := coderdenttest .NewWithDatabase (t , & coderdenttest.Options {
2128
2135
LicenseOptions : & coderdenttest.LicenseOptions {
2129
2136
Features : license.Features {
2130
2137
codersdk .FeatureExternalProvisionerDaemons : 1 ,
2131
2138
},
2132
2139
},
2133
2140
})
2141
+
2142
+ ctx := testutil .Context (t , testutil .WaitLong )
2143
+
2134
2144
userSubject , _ , err := httpmw .UserRBACSubject (ctx , db , userResponse .UserID , rbac .ExpandableScope (rbac .ScopeAll ))
2135
2145
require .NoError (t , err )
2136
2146
user , err := client .User (ctx , userSubject .ID )
@@ -2145,6 +2155,8 @@ func TestWorkspaceByOwnerAndName(t *testing.T) {
2145
2155
coderdtest .AwaitTemplateVersionJobCompleted (t , client , version .ID )
2146
2156
template := coderdtest .CreateTemplate (t , client , userResponse .OrganizationID , version .ID )
2147
2157
2158
+ ctx = testutil .Context (t , testutil .WaitLong ) // Reset the context to avoid timeouts.
2159
+
2148
2160
// nolint:gocritic // unit testing
2149
2161
daemons , err := db .GetProvisionerDaemons (dbauthz .AsSystemRestricted (ctx ))
2150
2162
require .NoError (t , err )
0 commit comments