Exemple #1
0
			By("using the baggage claim volumes ttl if the initial db lookup fails")
			fakeVolume.ExpirationReturns(expectedTTL, time.Now(), nil)
			fakeDB.GetVolumeTTLReturns(0, errors.New("disaster"))
			_, err := volumeFactory.Build(logger, fakeVolume)
			Expect(err).ToNot(HaveOccurred())
			By("using that ttl to heartbeat the volume initially")
			Expect(fakeVolume.SetTTLCallCount()).To(Equal(1))
			actualTTL := fakeVolume.SetTTLArgsForCall(0)
			Expect(actualTTL).To(Equal(expectedTTL))

			By("continuing to use the same ttl if the db continues to error")
			fakeClock.Increment(30 * time.Second)
			Eventually(fakeVolume.SetTTLCallCount).Should(Equal(2))
			actualTTL = fakeVolume.SetTTLArgsForCall(1)
			Expect(actualTTL).To(Equal(expectedTTL))
		})

		It("reaps the volume during heartbeat if the volume is not found", func() {
			fakeVolume.SetTTLReturns(baggageclaim.ErrVolumeNotFound)
			fakeVolume.HandleReturns("some-handle")

			_, err := volumeFactory.Build(logger, fakeVolume)
			Expect(err).ToNot(HaveOccurred())

			fakeClock.Increment(30 * time.Second)
			Expect(fakeDB.ReapVolumeCallCount()).To(Equal(1))
			Expect(fakeDB.ReapVolumeArgsForCall(0)).To(Equal("some-handle"))
		})
	})
})