Skip to content

Commit 525b8b3

Browse files
committed
ci: fix unit test failing in CI
1 parent ec67b0f commit 525b8b3

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

appender_test.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,37 @@ func TestAppenderRetry(t *testing.T) {
285285
addMinimalDoc(t, indexer, "logs-foo-testing")
286286
}
287287

288-
<-time.After(10 * time.Millisecond)
288+
bulkRequests := func() int64 {
289+
var rm metricdata.ResourceMetrics
290+
assert.NoError(t, rdr.Collect(context.Background(), &rm))
291+
292+
var res int64
293+
for _, m := range rm.ScopeMetrics[0].Metrics {
294+
if m.Name == "elasticsearch.bulk_requests.count" {
295+
counter := m.Data.(metricdata.Sum[int64])
296+
for _, dp := range counter.DataPoints {
297+
res += dp.Value
298+
}
299+
}
300+
}
301+
302+
return res
303+
}
304+
timeout := time.After(2 * time.Second)
305+
loop:
306+
for {
307+
select {
308+
case <-time.After(10 * time.Millisecond):
309+
// Because the internal channel is buffered to increase performance,
310+
// the available indexer may not take documents right away, loop until
311+
// the available bulk requests has been lowered.
312+
if bulkRequests() == 1 {
313+
break loop
314+
}
315+
case <-timeout:
316+
t.Fatalf("timed out waiting for the active bulk indexer to send one bulk request")
317+
}
318+
}
289319

290320
var rm metricdata.ResourceMetrics
291321
assert.NoError(t, rdr.Collect(context.Background(), &rm))
@@ -1764,7 +1794,7 @@ func TestAppenderScaling(t *testing.T) {
17641794
for a.IndexersActive() < n {
17651795
require.LessOrEqual(t, a.IndexersActive(), limit)
17661796
select {
1767-
case <-time.After(1000 * time.Millisecond):
1797+
case <-time.After(10 * time.Millisecond):
17681798
case <-timeout.C:
17691799
require.GreaterOrEqual(t, a.IndexersActive(), n)
17701800
}
@@ -1866,7 +1896,10 @@ func TestAppenderScaling(t *testing.T) {
18661896
sendDocuments(t, indexer, int(docs))
18671897

18681898
waitForScaleUp(t, indexer, 3)
1899+
waitForBulkRequests(t, indexer, rdr, docs)
1900+
18691901
waitForScaleDown(t, indexer, rdr, 1)
1902+
waitForBulkRequests(t, indexer, rdr, docs)
18701903

18711904
assert.Equal(t, int64(1), indexer.IndexersActive())
18721905

0 commit comments

Comments
 (0)