Ejemplo n.º 1
0
					Ω(fakeLockHandler.AddLockCallCount()).Should(Equal(1))
					lockName, lockContents, initiallyClaimed := fakeLockHandler.AddLockArgsForCall(0)
					Ω(lockName).Should(Equal("some-lock"))
					Ω(string(lockContents)).Should(Equal("lock-contents"))
					Ω(initiallyClaimed).Should(BeFalse())
				})

				Context("when adding the lock fails", func() {
					BeforeEach(func() {
						called := false

						fakeLockHandler.AddLockStub = func(_ string, _ []byte, _ bool) (string, error) {
							// succeed on second call
							if !called {
								called = true
								return "", errors.New("disaster")
							} else {
								return "some-ref", nil
							}
						}
					})

					It("does not return an error as it retries", func() {
						_, _, err := lockPool.AddUnclaimedLock(lockDir)
						Ω(err).ShouldNot(HaveOccurred())

						Ω(fakeLockHandler.AddLockCallCount()).Should(Equal(2))
					})
				})

				Context("when adding the lock succeeds", func() {
Ejemplo n.º 2
0
					Ω(fakeLockHandler.AddLockCallCount()).Should(Equal(1))
					lockName, lockContents := fakeLockHandler.AddLockArgsForCall(0)
					Ω(lockName).Should(Equal("some-lock"))
					Ω(string(lockContents)).Should(Equal("lock-contents"))
				})

				Context("when adding the lock fails", func() {
					BeforeEach(func() {
						called := false

						fakeLockHandler.AddLockStub = func(lockName string, lockContents []byte) (string, error) {
							// succeed on second call
							if !called {
								called = true
								return "", errors.New("disaster")
							} else {
								return "some-ref", nil
							}
						}
					})

					It("does not return an error as it retries", func() {
						_, _, err := lockPool.AddLock(lockDir)
						Ω(err).ShouldNot(HaveOccurred())

						Ω(fakeLockHandler.AddLockCallCount()).Should(Equal(2))
					})
				})

				Context("when adding the lock succeeds", func() {