writer = mockWriter{} writeStrategy = writestrategies.NewConstantWriteStrategy(&mockGenerator{}, &writer, 1000) }) Measure("writes messages at a constant rate", func(b Benchmarker) { go writeStrategy.StartWriter() time.Sleep(time.Millisecond * 50) writes := atomic.LoadUint32(&writer.count) Expect(writes).To(BeNumerically("~", 50, 10)) time.Sleep(time.Millisecond * 50) writes = atomic.LoadUint32(&writer.count) Expect(writes).To(BeNumerically("~", 100, 10)) writeStrategy.Stop() }, 1) Measure("stops writing messages when the stopChan is closed", func(b Benchmarker) { go writeStrategy.StartWriter() time.Sleep(time.Millisecond * 50) writes := atomic.LoadUint32(&writer.count) Expect(writes).To(BeNumerically(">", 40)) Expect(writes).To(BeNumerically("<", 60)) writeStrategy.Stop() time.Sleep(time.Millisecond * 50) writes = atomic.LoadUint32(&writer.count) Expect(writes).To(BeNumerically(">", 40))