Skip to content

Commit

Permalink
test: write large batches incrementally to avoid huge test time in Te…
Browse files Browse the repository at this point in the history
…stStorageLimit (#13281)

* test: write large batches incrementally to avoid huge test time in TestStorageLimit

To cause a badger error we are writing a batch of 150_000 * num_cpu events
This creates some delay on large systems which can be avoided since lower
batch size might be sufficient.
Incrementally send batches of 150_000 events to reduce test time.
Preliminary test shows 1-2 batches are enough to pass the test, lowering
the test time from 1.7s to 0.1s

* lint: make fmt
  • Loading branch information
kruskall authored Jun 3, 2024
1 parent c67adb9 commit 6309df6
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions x-pack/apm-server/sampling/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,14 +727,22 @@ func TestStorageLimit(t *testing.T) {
// Rather than setting a static threshold, use the runtime.NumCPU as a
// multiplier since the sharded writers use that variable and the more CPUs
// we have, the more sharded writes we'll have, resulting in a greater buffer.
processor := writeBatch(150_000*runtime.NumCPU(), config, func(b modelpb.Batch) {
assert.NotEmpty(t, b)
})
// To avoid huge test time on large systems do this incrementally
for i := 1; i < runtime.NumCPU(); i++ {
processor := writeBatch(150_000*i, config, func(b modelpb.Batch) {
assert.NotEmpty(t, b)
})

failedWrites := collectProcessorMetrics(processor).Ints["sampling.events.failed_writes"]
t.Log(failedWrites)
// Ensure that there are some failed writes.

if failedWrites >= 1 {
return
}
}

failedWrites := collectProcessorMetrics(processor).Ints["sampling.events.failed_writes"]
t.Log(failedWrites)
// Ensure that there are some failed writes.
assert.GreaterOrEqual(t, failedWrites, int64(1))
t.Fatal("badger error never thrown")
}

func TestProcessRemoteTailSamplingPersistence(t *testing.T) {
Expand Down

0 comments on commit 6309df6

Please sign in to comment.