mirror of
https://github.com/coder/coder.git
synced 2026-09-22 05:05:20 +08:00
test(coderd): enable dbrollup service for insights tests (#12673)
This commit is contained in:
@@ -21,7 +21,8 @@ const (
|
||||
)
|
||||
|
||||
type Event struct {
|
||||
TemplateUsageStats bool
|
||||
Init bool `json:"-"`
|
||||
TemplateUsageStats bool `json:"template_usage_stats"`
|
||||
}
|
||||
|
||||
type Rolluper struct {
|
||||
@@ -138,6 +139,15 @@ func (r *Rolluper) start(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// For testing.
|
||||
if r.event != nil {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case r.event <- Event{Init: true}:
|
||||
}
|
||||
}
|
||||
|
||||
// Perform do immediately and on every tick of the ticker,
|
||||
// disregarding the execution time of do. This ensure that
|
||||
// the rollup is performed every interval assuming do does
|
||||
|
||||
@@ -110,6 +110,8 @@ func TestRollup_TwoInstancesUseLocking(t *testing.T) {
|
||||
)
|
||||
defer closeRolluper(rolluper2, resume2)
|
||||
|
||||
_, _ = <-events1, <-events2 // Deplete init event, resume operation.
|
||||
|
||||
ctx := testutil.Context(t, testutil.WaitMedium)
|
||||
|
||||
// One of the rollup instances should roll up and the other should not.
|
||||
@@ -222,6 +224,8 @@ func TestRollupTemplateUsageStats(t *testing.T) {
|
||||
rolluper := dbrollup.New(logger, db, dbrollup.WithInterval(250*time.Millisecond), dbrollup.WithEventChannel(events))
|
||||
defer rolluper.Close()
|
||||
|
||||
<-events // Deplete init event, resume operation.
|
||||
|
||||
ctx := testutil.Context(t, testutil.WaitMedium)
|
||||
|
||||
select {
|
||||
|
||||
Reference in New Issue
Block a user