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())) }) }) Context("with another session", func() { It("acquires the lock when released", func() { bsession, err := consuladapter.NewSession("b-session", 20*time.Second, client, sessionMgr)
It("creates a new session", func() { Expect(newSessionErr).NotTo(HaveOccurred()) Expect(session).NotTo(BeNil()) }) Context("when a consul session is created", func() { JustBeforeEach(func() { err := session.AcquireLock("foo", []byte{}) Expect(err).NotTo(HaveOccurred()) }) It("has checks", func() { entries, _, err := client.Session().List(nil) Expect(err).NotTo(HaveOccurred()) session := findSession(session.ID(), entries) Expect(session.Checks).To(ConsistOf(serfCheckID)) }) Context("with no checks", func() { BeforeEach(func() { noChecks = true }) It("has no checks", func() { entries, _, err := client.Session().List(nil) Expect(err).NotTo(HaveOccurred()) session := findSession(session.ID(), entries) Expect(session.Checks).To(BeEmpty()) }) })