Skip to content

Commit b341c74

Browse files
author
andreaxia
committed
add step test
1 parent 4963673 commit b341c74

File tree

1 file changed

+70
-8
lines changed

1 file changed

+70
-8
lines changed

pkg/cachedtransactiongather/cachedtransactiongather_test.go

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,16 @@ func TestCache(t *testing.T) {
6565
promlogConfig := &promlog.Config{}
6666
cacheInterval := 60 * time.Second
6767
logger := promlog.New(promlogConfig)
68-
gather := NewCachedTransactionGather(
69-
newMultiConcurrencyRegistry(
70-
prometheus.ToTransactionalGatherer(newMockGatherer(time.Second*40)),
71-
prometheus.ToTransactionalGatherer(newMockGatherer(time.Second*23)),
72-
prometheus.ToTransactionalGatherer(newMockGatherer(time.Second*7)),
73-
),
74-
cacheInterval, logger,
75-
)
7668

7769
t.Run("gather with multiple calls should not error", func(t *testing.T) {
70+
gather := NewCachedTransactionGather(
71+
newMultiConcurrencyRegistry(
72+
prometheus.ToTransactionalGatherer(newMockGatherer(time.Second*40)),
73+
prometheus.ToTransactionalGatherer(newMockGatherer(time.Second*23)),
74+
prometheus.ToTransactionalGatherer(newMockGatherer(time.Second*7)),
75+
),
76+
cacheInterval, logger,
77+
)
7878
wait := sync.WaitGroup{}
7979
wait.Add(10)
8080
for range [10]int{} {
@@ -97,6 +97,14 @@ func TestCache(t *testing.T) {
9797
})
9898

9999
t.Run("gather success", func(t *testing.T) {
100+
gather := NewCachedTransactionGather(
101+
newMultiConcurrencyRegistry(
102+
prometheus.ToTransactionalGatherer(newMockGatherer(time.Second*40)),
103+
prometheus.ToTransactionalGatherer(newMockGatherer(time.Second*23)),
104+
prometheus.ToTransactionalGatherer(newMockGatherer(time.Second*7)),
105+
),
106+
cacheInterval, logger,
107+
)
100108
wait := sync.WaitGroup{}
101109
wait.Add(3)
102110
go func() {
@@ -131,4 +139,58 @@ func TestCache(t *testing.T) {
131139
}()
132140
wait.Wait()
133141
})
142+
143+
t.Run("gather with 5s step", func(t *testing.T) {
144+
gather := NewCachedTransactionGather(
145+
newMultiConcurrencyRegistry(
146+
prometheus.ToTransactionalGatherer(newMockGatherer(time.Second*40)),
147+
prometheus.ToTransactionalGatherer(newMockGatherer(time.Second*23)),
148+
prometheus.ToTransactionalGatherer(newMockGatherer(time.Second*7)),
149+
),
150+
cacheInterval, logger,
151+
)
152+
wait := sync.WaitGroup{}
153+
wait.Add(10)
154+
for range [10]int{} {
155+
time.Sleep(time.Second * 5)
156+
go func() {
157+
mfs, done, err := gather.Gather()
158+
defer done()
159+
if err != nil {
160+
logger.Log("err", err)
161+
t.Errorf("gather error: %v", err)
162+
}
163+
logger.Log("mfs", mfs, "done", "err", err)
164+
wait.Done()
165+
}()
166+
}
167+
wait.Wait()
168+
})
169+
170+
t.Run("gather with 65s step", func(t *testing.T) {
171+
gather := NewCachedTransactionGather(
172+
newMultiConcurrencyRegistry(
173+
prometheus.ToTransactionalGatherer(newMockGatherer(time.Second*40)),
174+
prometheus.ToTransactionalGatherer(newMockGatherer(time.Second*23)),
175+
prometheus.ToTransactionalGatherer(newMockGatherer(time.Second*7)),
176+
),
177+
cacheInterval, logger,
178+
)
179+
wait := sync.WaitGroup{}
180+
wait.Add(3)
181+
for range [3]int{} {
182+
time.Sleep(time.Second * 65)
183+
go func() {
184+
mfs, done, err := gather.Gather()
185+
defer done()
186+
if err != nil {
187+
logger.Log("err", err)
188+
t.Errorf("gather error: %v", err)
189+
}
190+
logger.Log("mfs", mfs, "done", "err", err)
191+
wait.Done()
192+
}()
193+
}
194+
wait.Wait()
195+
})
134196
}

0 commit comments

Comments
 (0)