@@ -9,6 +9,11 @@ import (
9
9
"strings"
10
10
"testing"
11
11
12
+ "cdr.dev/slog"
13
+ "cdr.dev/slog/sloggers/slogtest"
14
+
15
+ "github.com/coder/coder/v2/testutil"
16
+
12
17
"github.com/google/uuid"
13
18
"github.com/stretchr/testify/assert"
14
19
"github.com/stretchr/testify/require"
@@ -20,7 +25,6 @@ import (
20
25
"github.com/coder/coder/v2/coderd/database/dbfake"
21
26
"github.com/coder/coder/v2/codersdk"
22
27
"github.com/coder/coder/v2/provisionersdk/proto"
23
- "github.com/coder/coder/v2/pty/ptytest"
24
28
)
25
29
26
30
func TestWorkspaceAgent (t * testing.T ) {
@@ -44,17 +48,19 @@ func TestWorkspaceAgent(t *testing.T) {
44
48
"--log-dir" , logDir ,
45
49
)
46
50
47
- pty := ptytest . New ( t ). Attach ( inv )
48
-
51
+ // agent hits errors binding to ports for pprof, prometheus, etc., that don't affect the test
52
+ inv . Logger = slogtest . Make ( t , & slogtest. Options { IgnoreErrors : true }). Leveled ( slog . LevelDebug )
49
53
clitest .Start (t , inv )
50
- ctx := inv .Context ()
51
- pty .ExpectMatchContext (ctx , "agent is starting now" )
52
54
53
55
coderdtest .AwaitWorkspaceAgents (t , client , ws .ID )
54
56
55
- info , err := os .Stat (filepath .Join (logDir , "coder-agent.log" ))
56
- require .NoError (t , err )
57
- require .Greater (t , info .Size (), int64 (0 ))
57
+ require .Eventually (t , func () bool {
58
+ info , err := os .Stat (filepath .Join (logDir , "coder-agent.log" ))
59
+ if err != nil {
60
+ return false
61
+ }
62
+ return info .Size () > 0
63
+ }, testutil .WaitLong , testutil .IntervalMedium )
58
64
})
59
65
60
66
t .Run ("Azure" , func (t * testing.T ) {
@@ -84,6 +90,8 @@ func TestWorkspaceAgent(t *testing.T) {
84
90
//nolint:revive,staticcheck
85
91
context .WithValue (inv .Context (), "azure-client" , metadataClient ),
86
92
)
93
+ // agent hits errors binding to ports for pprof, prometheus, etc., that don't affect the test
94
+ inv .Logger = slogtest .Make (t , & slogtest.Options {IgnoreErrors : true }).Leveled (slog .LevelDebug )
87
95
ctx := inv .Context ()
88
96
clitest .Start (t , inv )
89
97
coderdtest .AwaitWorkspaceAgents (t , client , ws .ID )
@@ -126,6 +134,8 @@ func TestWorkspaceAgent(t *testing.T) {
126
134
//nolint:revive,staticcheck
127
135
context .WithValue (inv .Context (), "aws-client" , metadataClient ),
128
136
)
137
+ // agent hits errors binding to ports for pprof, prometheus, etc., that don't affect the test
138
+ inv .Logger = slogtest .Make (t , & slogtest.Options {IgnoreErrors : true }).Leveled (slog .LevelDebug )
129
139
clitest .Start (t , inv )
130
140
ctx := inv .Context ()
131
141
coderdtest .AwaitWorkspaceAgents (t , client , ws .ID )
@@ -164,8 +174,9 @@ func TestWorkspaceAgent(t *testing.T) {
164
174
}},
165
175
})
166
176
inv , cfg := clitest .New (t , "agent" , "--auth" , "google-instance-identity" , "--agent-url" , client .URL .String ())
167
- ptytest .New (t ).Attach (inv )
168
177
clitest .SetupConfig (t , member , cfg )
178
+ // agent hits errors binding to ports for pprof, prometheus, etc., that don't affect the test
179
+ inv .Logger = slogtest .Make (t , & slogtest.Options {IgnoreErrors : true }).Leveled (slog .LevelDebug )
169
180
clitest .Start (t ,
170
181
inv .WithContext (
171
182
//nolint:revive,staticcheck
@@ -223,10 +234,9 @@ func TestWorkspaceAgent(t *testing.T) {
223
234
// Set the subsystems for the agent.
224
235
inv .Environ .Set (agent .EnvAgentSubsystem , fmt .Sprintf ("%s,%s" , codersdk .AgentSubsystemExectrace , codersdk .AgentSubsystemEnvbox ))
225
236
226
- pty := ptytest . New ( t ). Attach ( inv )
227
-
237
+ // agent hits errors binding to ports for pprof, prometheus, etc., that don't affect the test
238
+ inv . Logger = slogtest . Make ( t , & slogtest. Options { IgnoreErrors : true }). Leveled ( slog . LevelDebug )
228
239
clitest .Start (t , inv )
229
- pty .ExpectMatchContext (inv .Context (), "agent is starting now" )
230
240
231
241
resources := coderdtest .AwaitWorkspaceAgents (t , client , ws .ID )
232
242
require .Len (t , resources , 1 )
0 commit comments