github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/topgun/both/pipeline_destroyed_test.go (about)

     1  package topgun_test
     2  
     3  import (
     4  	"time"
     5  
     6  	"code.cloudfoundry.org/garden"
     7  	. "github.com/pf-qiu/concourse/v6/topgun/common"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  )
    11  
    12  var _ = Describe("Garbage collecting containers for destroyed pipelines", func() {
    13  	BeforeEach(func() {
    14  		Deploy("deployments/concourse.yml")
    15  	})
    16  
    17  	It("should be removed", func() {
    18  		By("setting a pipeline")
    19  		Fly.Run("set-pipeline", "-n", "-c", "pipelines/get-task-put.yml", "-p", "pipeline-destroyed-test")
    20  
    21  		By("kicking off a build")
    22  		Fly.Run("unpause-pipeline", "-p", "pipeline-destroyed-test")
    23  		buildSession := Fly.Start("trigger-job", "-w", "-j", "pipeline-destroyed-test/simple-job")
    24  
    25  		<-buildSession.Exited
    26  		Expect(buildSession.ExitCode()).To(Equal(0))
    27  
    28  		By("verifying that containers exist")
    29  		containerTable := FlyTable("containers")
    30  		Expect(containerTable).To(HaveLen(7))
    31  
    32  		var (
    33  			err error
    34  		)
    35  		for _, c := range containerTable {
    36  			_, err = WorkerGardenClient.Lookup(c["handle"])
    37  			Expect(err).NotTo(HaveOccurred())
    38  		}
    39  
    40  		By("destroying the pipeline")
    41  		Fly.Run("destroy-pipeline", "-n", "-p", "pipeline-destroyed-test")
    42  
    43  		By("verifying the containers don't exist")
    44  		Eventually(func() int {
    45  			return len(FlyTable("containers"))
    46  		}, 5*time.Minute, 30*time.Second).Should(BeZero())
    47  
    48  		Eventually(func() []garden.Container {
    49  			containers, err := WorkerGardenClient.Containers(nil)
    50  			Expect(err).NotTo(HaveOccurred())
    51  
    52  			return containers
    53  		}, 5*time.Minute, 30*time.Second).Should(BeEmpty())
    54  	})
    55  })