Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f8d6f46

Browse files
committed
WIP
1 parent 3905481 commit f8d6f46

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

coderd/prometheusmetrics/prometheusmetrics_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,22 @@ import (
66
"testing"
77
"time"
88

9+
"sync/atomic"
10+
911
"github.com/google/uuid"
1012
"github.com/prometheus/client_golang/prometheus"
1113
"github.com/stretchr/testify/assert"
1214
"github.com/stretchr/testify/require"
1315

16+
"cdr.dev/slog/sloggers/slogtest"
17+
1418
"github.com/coder/coder/coderd/database"
1519
"github.com/coder/coder/coderd/database/dbfake"
1620
"github.com/coder/coder/coderd/database/dbgen"
1721
"github.com/coder/coder/coderd/prometheusmetrics"
1822
"github.com/coder/coder/codersdk"
23+
"github.com/coder/coder/tailnet"
24+
"github.com/coder/coder/tailnet/tailnettest"
1925
"github.com/coder/coder/testutil"
2026
)
2127

@@ -239,3 +245,37 @@ func TestWorkspaces(t *testing.T) {
239245
})
240246
}
241247
}
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

Comments
 (0)