stream.EventBuffer: Seed the fuzz test with time.Now()

Otherwise the test will run with exactly the same values each time.

By printing the seed we can attempt to reproduce the test by adding an env var to override the seed
This commit is contained in:
Daniel Nephin 2020-06-15 16:18:07 -04:00
parent 525b275a52
commit 7196917051
2 changed files with 6 additions and 5 deletions

View File

@ -33,7 +33,7 @@ import (
// the first event in the buffer, we can cache the buffered events for future // the first event in the buffer, we can cache the buffered events for future
// watchers on the same topic. Finally, once we've delivered all the snapshot // watchers on the same topic. Finally, once we've delivered all the snapshot
// events to the buffer, we can append a next-element which is the first topic // events to the buffer, we can append a next-element which is the first topic
// buffer element with a higher index and so consumers can just keep reading the // buffer element with a higher index and so consumers can keep reading the
// same buffer. // same buffer.
// //
// A huge benefit here is that caching snapshots becomes very simple - we don't // A huge benefit here is that caching snapshots becomes very simple - we don't
@ -124,9 +124,8 @@ func (b *EventBuffer) Head() *BufferItem {
} }
// BufferItem represents a set of events published by a single raft operation. // BufferItem represents a set of events published by a single raft operation.
// The first item returned by a newly constructed buffer will have nil Events // The first item returned by a newly constructed buffer will have nil Events.
// and should be considered a "sentinel" value just useful for waiting on the // It is a sentinel value which is used to wait on the next events via Next.
// next events via Next.
// //
// To iterate to the next event, a Next method may be called which may block if // To iterate to the next event, a Next method may be called which may block if
// there is no next element yet. // there is no next element yet.

View File

@ -26,10 +26,12 @@ func TestEventBufferFuzz(t *testing.T) {
// indexes and some jitter in timing (to allow clients to "catch up" and block // indexes and some jitter in timing (to allow clients to "catch up" and block
// waiting for updates). // waiting for updates).
go func() { go func() {
seed := time.Now().UnixNano()
t.Logf("Using seed %d", seed)
// z is a Zipfian distribution that gives us a number of milliseconds to // z is a Zipfian distribution that gives us a number of milliseconds to
// sleep which are mostly low - near zero but occasionally spike up to near // sleep which are mostly low - near zero but occasionally spike up to near
// 100. // 100.
z := rand.NewZipf(rand.New(rand.NewSource(1)), 1.5, 1.5, 50) z := rand.NewZipf(rand.New(rand.NewSource(seed)), 1.5, 1.5, 50)
for i := 0; i < nMessages; i++ { for i := 0; i < nMessages; i++ {
// Event content is arbitrary and not valid for our use of buffers in // Event content is arbitrary and not valid for our use of buffers in