MCPcopy Index your code
hub / github.com/coder/coder / TestTracker_TrackDuringFlush

Function TestTracker_TrackDuringFlush

coderd/boundaryusage/tracker_test.go:565–598  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

563}
564
565func TestTracker_TrackDuringFlush(t *testing.T) {
566 t.Parallel()
567
568 db, _ := dbtestutil.NewDB(t)
569 ctx := testutil.Context(t, testutil.WaitShort)
570 boundaryCtx := dbauthz.AsBoundaryUsageTracker(ctx)
571
572 tracker := boundaryusage.NewTracker()
573 replicaID := uuid.New()
574
575 // Track some initial data.
576 tracker.Track(uuid.New(), uuid.New(), 10, 5)
577
578 trackingDB := &trackDuringUpsertDB{
579 Store: db,
580 tracker: tracker,
581 workspaceID: uuid.New(),
582 userID: uuid.New(),
583 }
584
585 // Flush will call Track() during the DB operation.
586 err := tracker.FlushToDB(ctx, trackingDB, replicaID)
587 require.NoError(t, err)
588
589 // Second flush captures the Track() that happened during the first flush.
590 err = tracker.FlushToDB(ctx, db, replicaID)
591 require.NoError(t, err)
592
593 // Verify both flushes are in the summary.
594 summary, err := db.GetAndResetBoundaryUsageSummary(boundaryCtx, 60000)
595 require.NoError(t, err)
596 require.Equal(t, int64(10+20), summary.AllowedRequests)
597 require.Equal(t, int64(5+10), summary.DeniedRequests)
598}

Callers

nothing calls this directly

Calls 9

TrackMethod · 0.95
FlushToDBMethod · 0.95
NewDBFunction · 0.92
ContextFunction · 0.92
AsBoundaryUsageTrackerFunction · 0.92
NewTrackerFunction · 0.92
NewMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected