@@ -26,9 +26,11 @@ import (
26
26
"go.uber.org/goleak"
27
27
28
28
"github.com/coder/coder/cli/clitest"
29
+ "github.com/coder/coder/cli/config"
29
30
"github.com/coder/coder/coderd/database/postgres"
30
31
"github.com/coder/coder/coderd/telemetry"
31
32
"github.com/coder/coder/codersdk"
33
+ "github.com/coder/coder/internal/testutil"
32
34
"github.com/coder/coder/pty/ptytest"
33
35
)
34
36
@@ -56,13 +58,7 @@ func TestServer(t *testing.T) {
56
58
go func () {
57
59
errC <- root .ExecuteContext (ctx )
58
60
}()
59
- var rawURL string
60
- require .Eventually (t , func () bool {
61
- rawURL , err = cfg .URL ().Read ()
62
- return err == nil && rawURL != ""
63
- }, time .Minute , 50 * time .Millisecond )
64
- accessURL , err := url .Parse (rawURL )
65
- require .NoError (t , err )
61
+ accessURL := waitAccessURL (t , cfg )
66
62
client := codersdk .New (accessURL )
67
63
68
64
_ , err = client .CreateFirstUser (ctx , codersdk.CreateFirstUserRequest {
@@ -95,10 +91,7 @@ func TestServer(t *testing.T) {
95
91
go func () {
96
92
errC <- root .ExecuteContext (ctx )
97
93
}()
98
- require .Eventually (t , func () bool {
99
- accessURLRaw , err := cfg .URL ().Read ()
100
- return accessURLRaw != "" && err == nil
101
- }, 3 * time .Minute , 250 * time .Millisecond )
94
+ _ = waitAccessURL (t , cfg )
102
95
cancelFunc ()
103
96
require .ErrorIs (t , <- errC , context .Canceled )
104
97
})
@@ -133,11 +126,7 @@ func TestServer(t *testing.T) {
133
126
}()
134
127
135
128
// Just wait for startup
136
- require .Eventually (t , func () bool {
137
- var err error
138
- _ , err = cfg .URL ().Read ()
139
- return err == nil
140
- }, 15 * time .Second , 25 * time .Millisecond )
129
+ _ = waitAccessURL (t , cfg )
141
130
142
131
cancelFunc ()
143
132
require .ErrorIs (t , <- errC , context .Canceled )
@@ -213,14 +202,7 @@ func TestServer(t *testing.T) {
213
202
}()
214
203
215
204
// Verify HTTPS
216
- var accessURLRaw string
217
- require .Eventually (t , func () bool {
218
- var err error
219
- accessURLRaw , err = cfg .URL ().Read ()
220
- return accessURLRaw != "" && err == nil
221
- }, 15 * time .Second , 25 * time .Millisecond )
222
- accessURL , err := url .Parse (accessURLRaw )
223
- require .NoError (t , err )
205
+ accessURL := waitAccessURL (t , cfg )
224
206
require .Equal (t , "https" , accessURL .Scheme )
225
207
client := codersdk .New (accessURL )
226
208
client .HTTPClient = & http.Client {
@@ -258,11 +240,7 @@ func TestServer(t *testing.T) {
258
240
go func () {
259
241
serverErr <- root .ExecuteContext (ctx )
260
242
}()
261
- require .Eventually (t , func () bool {
262
- var err error
263
- _ , err = cfg .URL ().Read ()
264
- return err == nil
265
- }, 15 * time .Second , 25 * time .Millisecond )
243
+ _ = waitAccessURL (t , cfg )
266
244
currentProcess , err := os .FindProcess (os .Getpid ())
267
245
require .NoError (t , err )
268
246
err = currentProcess .Signal (os .Interrupt )
@@ -368,3 +346,17 @@ func generateTLSCertificate(t testing.TB) (certPath, keyPath string) {
368
346
require .NoError (t , err )
369
347
return certFile .Name (), keyFile .Name ()
370
348
}
349
+
350
+ func waitAccessURL (t * testing.T , cfg config.Root ) * url.URL {
351
+ var err error
352
+ var rawURL string
353
+ require .Eventually (t , func () bool {
354
+ rawURL , err = cfg .URL ().Read ()
355
+ return err == nil && rawURL != ""
356
+ }, testutil .WaitLong , testutil .IntervalFast )
357
+
358
+ accessURL , err := url .Parse (rawURL )
359
+ require .NoError (t , err )
360
+
361
+ return accessURL
362
+ }
0 commit comments