fakeLocker.AcquireWriteLockImmediatelyReturns(fakeLock, nil) }) Context("when the build is active", func() { BeforeEach(func() { model.Engine = "fake-engine-b" fakeBuildDB.GetBuildReturns(model, nil) fakeBuildDB.AbortBuildStub = func(int) error { Ω(fakeLocker.AcquireWriteLockImmediatelyCallCount()).Should(Equal(1)) lockedBuild := fakeLocker.AcquireWriteLockImmediatelyArgsForCall(0) Ω(lockedBuild).Should(Equal([]db.NamedLock{db.BuildTrackingLock(model.ID)})) Ω(fakeLock.ReleaseCallCount()).Should(BeZero()) return nil } }) Context("when the engine build exists", func() { var realBuild *fakes.FakeBuild BeforeEach(func() { fakeBuildDB.GetBuildReturns(model, nil) realBuild = new(fakes.FakeBuild) fakeEngineB.LookupBuildReturns(realBuild, nil) })
Eventually(times).Should(Receive(&time1)) Eventually(times).Should(Receive(&time2)) Ω(time2.Sub(time1)).Should(BeNumerically("~", interval, interval/4)) }) It("grabs a resource checking lock before checking, releases after done", func() { Eventually(times).Should(Receive()) Ω(locker.AcquireWriteLockImmediatelyCallCount()).Should(Equal(1)) lockedInputs := locker.AcquireWriteLockImmediatelyArgsForCall(0) Ω(lockedInputs).Should(Equal([]db.NamedLock{db.ResourceCheckingLock("pipeline:some-resource")})) Ω(writeImmediatelyLock.ReleaseCallCount()).Should(Equal(1)) }) It("releases after checking", func() { Eventually(times).Should(Receive()) Ω(fakeResource.ReleaseCallCount()).Should(Equal(1)) }) Context("when there is no current version", func() { It("checks from nil", func() { Eventually(times).Should(Receive()) _, version := fakeResource.CheckArgsForCall(0) Ω(version).Should(BeNil()) })