Exemplo n.º 1
0
				BeforeEach(func() {
					fakeLockHandler.ResetLockReturns(errors.New("some-error"))
				})

				It("returns an error", func() {
					_, err := lockPool.ClaimLock("some-lock")
					Ω(err).Should(HaveOccurred())
				})
			})

			Context("when resetting the lock succeeds", func() {
				It("tries to claim the specific lock", func() {
					_, err := lockPool.ClaimLock("some-lock")
					Ω(err).ShouldNot(HaveOccurred())

					Ω(fakeLockHandler.ClaimLockCallCount()).Should(Equal(1))
					Ω(fakeLockHandler.ClaimLockArgsForCall(0)).Should(Equal("some-lock"))
				})

				Context("when attempting to claim a lock fails", func() {
					BeforeEach(func() {
						called := false

						fakeLockHandler.ClaimLockStub = func(lock string) (string, error) {
							// succeed on second call
							if !called {
								called = true
								return "", errors.New("disaster")
							} else {
								return "", nil
							}