示例#1
0
					fakeWorker = new(fakes.FakeWorker)
					fakeProvider.GetWorkerReturns(fakeWorker, true, nil)
				})

				It("calls to lookup the container on the worker", func() {
					pool.LookupContainer(logger, "some-handle")

					Expect(fakeWorker.LookupContainerCallCount()).To(Equal(1))

					_, handleArg := fakeWorker.LookupContainerArgsForCall(0)
					Expect(handleArg).To(Equal("some-handle"))
				})

				Context("when looking up the container contains an error", func() {
					It("returns the error", func() {
						fakeWorker.LookupContainerReturns(nil, false, errors.New("disaster"))

						container, found, err := pool.LookupContainer(logger, "some-handle")
						Expect(err).To(HaveOccurred())
						Expect(container).To(BeNil())
						Expect(found).To(BeFalse())
					})
				})

				Context("when the container cannot be found on the worker", func() {
					BeforeEach(func() {
						fakeWorker.LookupContainerReturns(nil, false, nil)
					})

					It("expires the container and returns false and no error", func() {
						_, found, err := pool.LookupContainer(logger, "some-handle")
示例#2
0
文件: pool_test.go 项目: utako/atc
			BeforeEach(func() {
				workerA = new(fakes.FakeWorker)
				workerB = new(fakes.FakeWorker)

				workerA.ActiveContainersReturns(3)
				workerB.ActiveContainersReturns(2)

				fakeContainer = new(fakes.FakeContainer)
				fakeContainer.HandleReturns("fake-container")

				fakeProvider.WorkersReturns([]Worker{workerA, workerB}, nil)
			})

			Context("when a worker can locate the container", func() {
				BeforeEach(func() {
					workerA.LookupContainerReturns(fakeContainer, nil)
					workerB.LookupContainerReturns(nil, ErrContainerNotFound)
				})

				It("returns the container", func() {
					Ω(foundContainer).Should(Equal(fakeContainer))
				})

				It("looks up by the given identifier", func() {
					Ω(workerA.LookupContainerCallCount()).Should(Equal(1))
					Ω(workerB.LookupContainerCallCount()).Should(Equal(1))

					Ω(workerA.LookupContainerArgsForCall(0)).Should(Equal(id))
					Ω(workerB.LookupContainerArgsForCall(0)).Should(Equal(id))
				})
			})