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

Skip to content

Commit da902a8

Browse files
committed
allow blocking rollup init to handle data insertion
1 parent 60d812d commit da902a8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

coderd/database/dbrollup/dbrollup.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ const (
2121
)
2222

2323
type Event struct {
24-
TemplateUsageStats bool
24+
Init bool `json:"-"`
25+
TemplateUsageStats bool `json:"template_usage_stats"`
2526
}
2627

2728
type Rolluper struct {
@@ -138,6 +139,15 @@ func (r *Rolluper) start(ctx context.Context) {
138139
}
139140
}
140141

142+
// For testing.
143+
if r.event != nil {
144+
select {
145+
case <-ctx.Done():
146+
return
147+
case r.event <- Event{Init: true}:
148+
}
149+
}
150+
141151
// Perform do immediately and on every tick of the ticker,
142152
// disregarding the execution time of do. This ensure that
143153
// the rollup is performed every interval assuming do does

coderd/database/dbrollup/dbrollup_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ func TestRollup_TwoInstancesUseLocking(t *testing.T) {
110110
)
111111
defer closeRolluper(rolluper2, resume2)
112112

113+
_, _ = <-events1, <-events2 // Deplete init event, resume operation.
114+
113115
ctx := testutil.Context(t, testutil.WaitMedium)
114116

115117
// One of the rollup instances should roll up and the other should not.
@@ -222,6 +224,8 @@ func TestRollupTemplateUsageStats(t *testing.T) {
222224
rolluper := dbrollup.New(logger, db, dbrollup.WithInterval(250*time.Millisecond), dbrollup.WithEventChannel(events))
223225
defer rolluper.Close()
224226

227+
<-events // Deplete init event, resume operation.
228+
225229
ctx := testutil.Context(t, testutil.WaitMedium)
226230

227231
select {

0 commit comments

Comments
 (0)