예제 #1
0
	BeforeEach(func() {
		team, err := sqlDB.SaveTeam(db.Team{Name: "some-team"})
		Expect(err).NotTo(HaveOccurred())
		_, _, err = sqlDB.SaveConfig(team.Name, "pipeline-name", pipelineConfig, 0, db.PipelineUnpaused)
		Expect(err).NotTo(HaveOccurred())

		savedPipeline, err := sqlDB.GetPipelineByTeamNameAndName(team.Name, "pipeline-name")
		Expect(err).NotTo(HaveOccurred())

		pipelineDB = pipelineDBFactory.Build(savedPipeline)
	})

	Describe("taking out a lease on pipeline scheduling", func() {
		Context("when it has been scheduled recently", func() {
			It("does not get the lease", func() {
				lease, leased, err := pipelineDB.LeaseScheduling(1 * time.Second)
				Expect(err).NotTo(HaveOccurred())
				Expect(leased).To(BeTrue())

				lease.Break()

				_, leased, err = pipelineDB.LeaseScheduling(1 * time.Second)
				Expect(err).NotTo(HaveOccurred())
				Expect(leased).To(BeFalse())
			})
		})

		Context("when there has not been any scheduling recently", func() {
			It("gets and keeps the lease and stops others from getting it", func() {
				lease, leased, err := pipelineDB.LeaseScheduling(1 * time.Second)
				Expect(err).NotTo(HaveOccurred())