BeforeEach(func() { operation1 = new(fake_operationq.FakeOperation) operation2 = new(fake_operationq.FakeOperation) fakeGenerator.BatchOperationsStub = func(lager.Logger) (map[string]operationq.Operation, error) { fakeClock.Increment(10 * time.Second) return map[string]operationq.Operation{"guid1": operation1, "guid2": operation2}, nil } }) It("pushes them onto the queue", func() { Eventually(fakeQueue.PushCallCount).Should(Equal(2)) enqueuedOperations := make([]operationq.Operation, 0, 2) enqueuedOperations = append(enqueuedOperations, fakeQueue.PushArgsForCall(0)) enqueuedOperations = append(enqueuedOperations, fakeQueue.PushArgsForCall(1)) Expect(enqueuedOperations).To(ConsistOf(operation1, operation2)) }) It("emits the duration it took to generate the batch operations", func() { Eventually(fakeQueue.PushCallCount).Should(Equal(2)) reportedDuration := sender.GetValue("RepBulkSyncDuration") Expect(reportedDuration.Unit).To(Equal("nanos")) Expect(reportedDuration.Value).To(BeNumerically("==", 10*time.Second)) }) }) Context("when generating the batch operations fails", func() {
fakeGenerator.OperationStreamReturns(operations, nil) }) Context("when an operation is received", func() { var fakeOperation *fake_operationq.FakeOperation BeforeEach(func() { fakeOperation = new(fake_operationq.FakeOperation) }) It("pushes it onto the queue", func() { receivedOperations <- fakeOperation Eventually(fakeQueue.PushCallCount).Should(Equal(1)) Expect(fakeQueue.PushArgsForCall(0)).To(Equal(fakeOperation)) }) }) Context("when the operation stream terminates", func() { It("exits happily", func() { close(receivedOperations) Eventually(process.Wait()).Should(Receive(BeNil())) }) }) }) Context("when subscribing to events fails", func() { disaster := errors.New("nope")