Beispiel #1
0
			Expect(err).NotTo(HaveOccurred())
		})

		JustBeforeEach(func() {
			process = startBulker(false)
		})

		AfterEach(func() {
			ginkgomon.Interrupt(process, interruptTimeout)
		})

		itIsMissingDomain()

		Context("when the lock becomes available", func() {
			BeforeEach(func() {
				otherSession.Destroy()

				time.Sleep(pollingInterval + 10*time.Millisecond)
			})

			It("is updated", func() {
				Eventually(func() ([]string, error) {
					logger := logger.Session("domain-polling")
					logger.Debug("getting-domains")
					domains, err := bbsClient.Domains()
					logger.Debug("finished-getting-domains", lager.Data{"domains": domains, "error": err})
					return domains, err
				}, 4*domainTTL).Should(ContainElement("cf-apps"))
			})
		})
	})
			var err error
			client = clusterRunner.NewClient()

			disappearChan = session.WatchForDisappearancesUnder(logger, "under")
			Expect(err).NotTo(HaveOccurred())
		})

		Context("when there are keys", func() {
			var bsession *consuladapter.Session

			BeforeEach(func() {
				bsession = clusterRunner.NewSession("bsession")
			})

			AfterEach(func() {
				bsession.Destroy()
			})

			It("detects removals of keys", func() {
				_, err := bsession.SetPresence("under/here", []byte("value"))
				Expect(err).NotTo(HaveOccurred())

				bsession.Destroy()

				Eventually(disappearChan).Should(Receive(Equal([]string{"under/here"})))
			})

			Context("with other prefixes", func() {
				BeforeEach(func() {
					_, err := bsession.SetPresence("other", []byte("value"))
					Expect(err).NotTo(HaveOccurred())
				It("returns an error", func() {
					Expect(lockErr).To(Equal(consuladapter.ErrCancelled))
				})
			})

			Context("when recreating the Session", func() {
				var newSession *consuladapter.Session

				JustBeforeEach(func() {
					var err error
					newSession, err = session.Recreate()
					Expect(err).NotTo(HaveOccurred())
				})

				AfterEach(func() {
					newSession.Destroy()
				})

				It("creates a new session", func() {
					Expect(newSession.ID()).NotTo(Equal(session.ID()))
				})

				It("can contend for the Lock", func() {
					errCh := make(chan error, 1)
					go func() {
						errCh <- newSession.AcquireLock(lockKey, lockValue)
					}()

					Eventually(errCh).Should(Receive(BeNil()))
				})
			})
		client = clusterRunner.NewClient()
		sessionMgr = newFakeSessionManager(client)
		noChecks = false
	})

	JustBeforeEach(func() {
		if noChecks {
			session, newSessionErr = consuladapter.NewSessionNoChecks("a-session", 20*time.Second, client, sessionMgr)
		} else {
			session, newSessionErr = consuladapter.NewSession("a-session", 20*time.Second, client, sessionMgr)
		}
	})

	AfterEach(func() {
		if session != nil {
			session.Destroy()
		}
	})

	Describe("NewSession", func() {
		Context("when consul is down", func() {
			BeforeEach(stopCluster)

			It("a session can be created", func() {
				Expect(newSessionErr).NotTo(HaveOccurred())
				Expect(session).NotTo(BeNil())
			})
		})

		It("creates a new session", func() {
			Expect(newSessionErr).NotTo(HaveOccurred())