Context("ConstantWriteStrategy", func() { Describe("StartWriter", func() { var ( writer mockWriter stopChan chan struct{} writeStrategy *writestrategies.ConstantWriteStrategy ) BeforeEach(func() { writer = mockWriter{} stopChan = make(chan struct{}) writeStrategy = writestrategies.NewConstantWriteStrategy(&mockGenerator{}, &writer, 1000) }) It("writes messages at a constant rate", func() { go writeStrategy.StartWriter(stopChan) time.Sleep(time.Millisecond * 50) writes := atomic.LoadUint32(&writer.count) Expect(writes).To(BeNumerically(">", 40)) Expect(writes).To(BeNumerically("<", 60)) time.Sleep(time.Millisecond * 50) writes = atomic.LoadUint32(&writer.count) Expect(writes).To(BeNumerically(">", 90)) Expect(writes).To(BeNumerically("<", 110)) close(stopChan) }) It("stops writing messages when the stopChan is closed", func() {
var _ = Describe("WriteStrategies", func() { Context("ConstantWriteStrategy", func() { Describe("StartWriter", func() { var ( writer mockWriter writeStrategy *writestrategies.ConstantWriteStrategy ) BeforeEach(func() { 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()