@@ -6,16 +6,22 @@ import (
6
6
"testing"
7
7
"time"
8
8
9
+ "sync/atomic"
10
+
9
11
"github.com/google/uuid"
10
12
"github.com/prometheus/client_golang/prometheus"
11
13
"github.com/stretchr/testify/assert"
12
14
"github.com/stretchr/testify/require"
13
15
16
+ "cdr.dev/slog/sloggers/slogtest"
17
+
14
18
"github.com/coder/coder/coderd/database"
15
19
"github.com/coder/coder/coderd/database/dbfake"
16
20
"github.com/coder/coder/coderd/database/dbgen"
17
21
"github.com/coder/coder/coderd/prometheusmetrics"
18
22
"github.com/coder/coder/codersdk"
23
+ "github.com/coder/coder/tailnet"
24
+ "github.com/coder/coder/tailnet/tailnettest"
19
25
"github.com/coder/coder/testutil"
20
26
)
21
27
@@ -239,3 +245,37 @@ func TestWorkspaces(t *testing.T) {
239
245
})
240
246
}
241
247
}
248
+
249
+ func TestAgents (t * testing.T ) {
250
+ t .Parallel ()
251
+
252
+ // given
253
+ db := dbfake .New ()
254
+
255
+ coordinator := tailnet .NewCoordinator ()
256
+ coordinatorPtr := atomic.Pointer [tailnet.Coordinator ]{}
257
+ coordinatorPtr .Store (& coordinator )
258
+ derpMap := tailnettest .RunDERPAndSTUN (t )
259
+ agentInactiveDisconnectTimeout := 1 * time .Hour
260
+ registry := prometheus .NewRegistry ()
261
+
262
+ // when
263
+ cancel , err := prometheusmetrics .Agents (context .Background (), slogtest .Make (t , nil ), registry , db , & coordinatorPtr , derpMap , agentInactiveDisconnectTimeout , time .Millisecond )
264
+ t .Cleanup (cancel )
265
+
266
+ // then
267
+ require .NoError (t , err )
268
+ require .Eventually (t , func () bool {
269
+ metrics , err := registry .Gather ()
270
+ assert .NoError (t , err )
271
+
272
+ if len (metrics ) < 1 {
273
+ return false
274
+ }
275
+
276
+ for _ , metric := range metrics [0 ].Metric {
277
+ panic (metric )
278
+ }
279
+ return true
280
+ }, testutil .WaitShort , testutil .IntervalFast )
281
+ }
0 commit comments