github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/topgun/runtime/atc_rebalance_test.go (about) 1 package topgun_test 2 3 import ( 4 "os" 5 "strings" 6 "time" 7 8 . "github.com/pf-qiu/concourse/v6/topgun/common" 9 _ "github.com/lib/pq" 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 "github.com/onsi/gomega/gbytes" 13 "github.com/onsi/gomega/gexec" 14 ) 15 16 var _ = Describe("Rebalancing workers", func() { 17 var rebalanceInterval = 5 * time.Second 18 19 Context("with two TSAs available", func() { 20 var webInstances []BoshInstance 21 22 BeforeEach(func() { 23 Deploy( 24 "deployments/concourse.yml", 25 "-o", "operations/web-instances.yml", 26 "-v", "web_instances=2", 27 "-o", "operations/worker-rebalancing.yml", 28 "-v", "rebalance_interval="+rebalanceInterval.String(), 29 ) 30 31 WaitForRunningWorker() 32 33 webInstances = JobInstances("web") 34 }) 35 36 It("rotates the worker to between both web nodes over a period of time", func() { 37 Eventually(func() string { 38 workers := FlyTable("workers", "-d") 39 return strings.Split(workers[0]["garden address"], ":")[0] 40 }).Should(SatisfyAny( 41 Equal(webInstances[0].IP), 42 Equal(webInstances[0].DNS), 43 )) 44 45 Eventually(func() string { 46 workers := FlyTable("workers", "-d") 47 return strings.Split(workers[0]["garden address"], ":")[0] 48 }).Should(SatisfyAny( 49 Equal(webInstances[1].IP), 50 Equal(webInstances[1].DNS), 51 )) 52 }) 53 54 Context("while the worker is draining", func() { 55 var buildSession *gexec.Session 56 var boshStopSession *gexec.Session 57 58 BeforeEach(func() { 59 buildSession = Fly.Start("execute", "-c", "tasks/wait.yml") 60 Eventually(buildSession).Should(gbytes.Say("executing build")) 61 Eventually(buildSession).Should(gbytes.Say("waiting for /tmp/stop-waiting")) 62 63 boshStopSession = SpawnBosh("stop", "worker/0") 64 Eventually(WaitForWorkerInState("retiring")).ShouldNot(BeEmpty()) 65 }) 66 67 AfterEach(func() { 68 buildSession.Signal(os.Interrupt) 69 <-buildSession.Exited 70 71 <-boshStopSession.Exited 72 Bosh("start", "worker/0") 73 }) 74 75 It("does not rebalance", func() { 76 originalAddr := FlyTable("workers", "-d")[0]["garden address"] 77 Expect(originalAddr).ToNot(BeEmpty()) 78 79 Consistently(func() string { 80 worker := FlyTable("workers", "-d")[0] 81 Expect(worker["state"]).To(Equal("retiring")) 82 83 return worker["garden address"] 84 }, 3*rebalanceInterval).Should(Equal(originalAddr)) 85 }) 86 }) 87 }) 88 })