zapcore: Unflake TestSamplerConcurrent #1012
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The TestSamplerConcurrent test frequently fails with the following error
in CI:
The test is intended to verify that
despite an onsalught of messages from multiple goroutines,
we only allow at most
logsPerTick
messages pertick
.This was accompilshed by spin-looping 10 goroutines for
numTicks
,each logging one of
numMessages
different messages,and then verifying the final log count.
The source of flakiness here was the non-determinism in
how far a goroutine would get in logging enough messages such that
the sampler would be engaged.
In #948, we added a
zapcore.Clock
interface with a ticker anda mock implementation.
Move that to
ztest
for use here.To unflake the test, use the mock clock to control time and
for each goroutine, log
logsPerTick*2
messagesnumTicks
times.This gives us,
We end up attempting to log a total of,
Of these, the following should be sampled:
Everything else should be dropped.
For extra confidence, use a SamplerHook (added in #813) to verify that
the number of sampled and dropped messages meet expectations.
Refs GO-873