Exemple #1
0
				time.Sleep(time.Second)

				newLease, leased, err := sqlDB.LeaseBuildTracking(buildID, 1*time.Second)
				Expect(err).NotTo(HaveOccurred())
				Expect(leased).To(BeTrue())

				newLease.Break()
			})
		})
	})

	Describe("taking out a lease on cache invalidation", func() {
		Context("when something has been invalidating the cache recently", func() {
			It("does not get the lease", func() {
				lease, leased, err := sqlDB.LeaseCacheInvalidation(1 * time.Second)
				Expect(err).NotTo(HaveOccurred())
				Expect(leased).To(BeTrue())

				lease.Break()

				_, leased, err = sqlDB.LeaseCacheInvalidation(1 * time.Second)
				Expect(err).NotTo(HaveOccurred())
				Expect(leased).To(BeFalse())
			})
		})

		Context("when there has not been any cache invalidation recently", func() {
			It("gets and keeps the lease and stops others from getting it", func() {
				lease, leased, err := sqlDB.LeaseCacheInvalidation(1 * time.Second)
				Expect(err).NotTo(HaveOccurred())