(t *testing.T)
| 563 | } |
| 564 | |
| 565 | func 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 | } |
nothing calls this directly
no test coverage detected