Example #1
0
			Ω(locker.AcquireWriteLockCallCount()).Should(Equal(1))

			lockedInputs := locker.AcquireWriteLockArgsForCall(0)
			Ω(lockedInputs).Should(Equal([]db.NamedLock{db.ResourceCheckingLock("pipeline:some-resource")}))

			Ω(writeLock.ReleaseCallCount()).Should(Equal(1))
		})

		It("releases the resource", func() {
			Ω(fakeResource.ReleaseCallCount()).Should(Equal(1))
		})

		It("clears the resource's check error", func() {
			Ω(fakeRadarDB.SetResourceCheckErrorCallCount()).Should(Equal(1))

			savedResourceArg, err := fakeRadarDB.SetResourceCheckErrorArgsForCall(0)
			Ω(savedResourceArg).Should(Equal(savedResource))
			Ω(err).Should(BeNil())
		})

		Context("when there is no current version", func() {
			It("checks from nil", func() {
				_, version := fakeResource.CheckArgsForCall(0)
				Ω(version).Should(BeNil())
			})
		})

		Context("when there is a current version", func() {
			BeforeEach(func() {
				fakeRadarDB.GetLatestVersionedResourceReturns(
					db.SavedVersionedResource{
Example #2
0
				Context("when the interval cannot be parsed", func() {
					BeforeEach(func() {
						resourceConfig.CheckEvery = "bad-value"

						fakeRadarDB.GetConfigReturns(atc.Config{
							Resources: atc.ResourceConfigs{
								resourceConfig,
							},
						}, 1, true, nil)
					})

					It("sets the check error and exits with the error", func() {
						Expect(<-process.Wait()).To(HaveOccurred())
						Expect(fakeRadarDB.SetResourceCheckErrorCallCount()).To(Equal(1))

						resourceName, resourceErr := fakeRadarDB.SetResourceCheckErrorArgsForCall(0)
						Expect(resourceName).To(Equal(savedResource))
						Expect(resourceErr).To(MatchError("time: invalid duration bad-value"))
					})
				})
			})

			It("grabs a periodic resource checking lease before checking, breaks lease after done", func() {
				<-times

				Expect(fakeRadarDB.LeaseResourceCheckingCallCount()).To(Equal(1))

				resourceName, leaseInterval, immediate := fakeRadarDB.LeaseResourceCheckingArgsForCall(0)
				Expect(resourceName).To(Equal("some-resource"))
				Expect(leaseInterval).To(Equal(interval))
				Expect(immediate).To(BeFalse())