Ejemplo n.º 1
0
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"

	"github.com/concourse/pool-resource/out"
	fakes "github.com/concourse/pool-resource/out/fakes"
)

var _ = Describe("Lock Pool", func() {
	var lockPool out.LockPool
	var fakeLockHandler *fakes.FakeLockHandler
	var output *gbytes.Buffer

	ValidateSharedBehaviorDuringBroadcastFailures := func(operationUnderTest func() error, additionalValidation func(int)) {

		ValidateInteractionsWithLockHandler := func(expectedNumberOfInteractions int) {
			Ω(fakeLockHandler.BroadcastLockPoolCallCount()).Should(Equal(expectedNumberOfInteractions))
			additionalValidation(expectedNumberOfInteractions)
		}

		Context("when broadcasting fails with ", func() {
			Context("for an unexpected reason", func() {
				BeforeEach(func() {
					called := false

					fakeLockHandler.BroadcastLockPoolStub = func() ([]byte, error) {
						// succeed on second call
						if !called {
							called = true
							return nil, errors.New("disaster")
						} else {
							return nil, nil
Ejemplo n.º 2
0
							_, _, err := lockPool.RemoveLock(lockDir)
							Ω(err).Should(HaveOccurred())
							Ω(fakeLockHandler.RemoveLockCallCount()).Should(Equal(1))
						})
					})

					Context("when removing the lock succeeds", func() {
						BeforeEach(func() {
							fakeLockHandler.RemoveLockReturns("some-ref", nil)
						})

						It("tries to broadcast to the lock pool", func() {
							_, _, err := lockPool.RemoveLock(lockDir)
							Ω(err).ShouldNot(HaveOccurred())

							Ω(fakeLockHandler.BroadcastLockPoolCallCount()).Should(Equal(1))
						})

						Context("when broadcasting fails with ", func() {
							Context("for an unexpected reason", func() {
								BeforeEach(func() {
									called := false

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