github.com/chenbh/concourse/v6@v6.4.2/atc/gc/worker_collector_test.go (about) 1 package gc_test 2 3 import ( 4 "context" 5 6 "github.com/chenbh/concourse/v6/atc/gc" 7 8 "errors" 9 10 "github.com/chenbh/concourse/v6/atc/db/dbfakes" 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/gomega" 13 ) 14 15 var _ = Describe("WorkerCollector", func() { 16 var ( 17 workerCollector GcCollector 18 fakeWorkerLifecycle *dbfakes.FakeWorkerLifecycle 19 ) 20 21 BeforeEach(func() { 22 fakeWorkerLifecycle = new(dbfakes.FakeWorkerLifecycle) 23 24 workerCollector = gc.NewWorkerCollector(fakeWorkerLifecycle) 25 26 fakeWorkerLifecycle.DeleteUnresponsiveEphemeralWorkersReturns(nil, nil) 27 fakeWorkerLifecycle.StallUnresponsiveWorkersReturns(nil, nil) 28 fakeWorkerLifecycle.DeleteFinishedRetiringWorkersReturns(nil, nil) 29 fakeWorkerLifecycle.LandFinishedLandingWorkersReturns(nil, nil) 30 }) 31 32 Describe("Run", func() { 33 It("tells the worker factory to delete unresponsive ephemeral workers", func() { 34 err := workerCollector.Run(context.TODO()) 35 Expect(err).NotTo(HaveOccurred()) 36 37 Expect(fakeWorkerLifecycle.DeleteUnresponsiveEphemeralWorkersCallCount()).To(Equal(1)) 38 }) 39 40 It("tells the worker factory to expired stalled workers", func() { 41 err := workerCollector.Run(context.TODO()) 42 Expect(err).NotTo(HaveOccurred()) 43 44 Expect(fakeWorkerLifecycle.StallUnresponsiveWorkersCallCount()).To(Equal(1)) 45 }) 46 47 It("tells the worker factory to delete finished retiring workers", func() { 48 err := workerCollector.Run(context.TODO()) 49 Expect(err).NotTo(HaveOccurred()) 50 51 Expect(fakeWorkerLifecycle.DeleteFinishedRetiringWorkersCallCount()).To(Equal(1)) 52 }) 53 54 It("tells the worker factory to land finished landing workers", func() { 55 err := workerCollector.Run(context.TODO()) 56 Expect(err).NotTo(HaveOccurred()) 57 58 Expect(fakeWorkerLifecycle.LandFinishedLandingWorkersCallCount()).To(Equal(1)) 59 }) 60 61 It("returns an error if stalling unresponsive workers fails", func() { 62 returnedErr := errors.New("some-error") 63 fakeWorkerLifecycle.StallUnresponsiveWorkersReturns(nil, returnedErr) 64 65 err := workerCollector.Run(context.TODO()) 66 Expect(err).To(MatchError(returnedErr)) 67 }) 68 69 It("returns an error if deleting finished retiring workers fails", func() { 70 returnedErr := errors.New("some-error") 71 fakeWorkerLifecycle.DeleteFinishedRetiringWorkersReturns(nil, returnedErr) 72 73 err := workerCollector.Run(context.TODO()) 74 Expect(err).To(MatchError(returnedErr)) 75 }) 76 77 It("returns an error if landing finished landing workers fails", func() { 78 returnedErr := errors.New("some-error") 79 fakeWorkerLifecycle.LandFinishedLandingWorkersReturns(nil, returnedErr) 80 81 err := workerCollector.Run(context.TODO()) 82 Expect(err).To(MatchError(returnedErr)) 83 }) 84 85 }) 86 })