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

     1  package topgun_test
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	. "github.com/pf-qiu/concourse/v6/topgun/common"
     8  	_ "github.com/lib/pq"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  )
    12  
    13  var _ = Describe("Garbage collecting resource containers", func() {
    14  	Describe("A container that is used by resource checking on freshly deployed worker", func() {
    15  		BeforeEach(func() {
    16  			Deploy(
    17  				"deployments/concourse.yml",
    18  				"-o", "operations/worker-instances.yml",
    19  				"-v", "worker_instances=2",
    20  			)
    21  		})
    22  
    23  		It("is recreated in database and worker", func() {
    24  			By("setting pipeline that creates resource cache")
    25  			Fly.Run("set-pipeline", "-n", "-c", "pipelines/get-task-changing-resource.yml", "-p", "volume-gc-test")
    26  
    27  			By("unpausing the pipeline")
    28  			Fly.Run("unpause-pipeline", "-p", "volume-gc-test")
    29  
    30  			By("checking resource")
    31  			Fly.Run("check-resource", "-r", "volume-gc-test/tick-tock")
    32  
    33  			By("getting the resource config container")
    34  			containers := FlyTable("containers")
    35  			var checkContainerHandle string
    36  			for _, container := range containers {
    37  				if container["type"] == "check" {
    38  					checkContainerHandle = container["handle"]
    39  					break
    40  				}
    41  			}
    42  			Expect(checkContainerHandle).NotTo(BeEmpty())
    43  
    44  			By(fmt.Sprintf("eventually expiring the resource config container: %s", checkContainerHandle))
    45  			Eventually(func() bool {
    46  				containers := FlyTable("containers")
    47  				for _, container := range containers {
    48  					if container["type"] == "check" && container["handle"] == checkContainerHandle {
    49  						return true
    50  					}
    51  				}
    52  				return false
    53  			}, 10*time.Minute, 10*time.Second).Should(BeFalse())
    54  
    55  			By("checking resource again")
    56  			Fly.Run("check-resource", "-r", "volume-gc-test/tick-tock")
    57  
    58  			By("getting the resource config container")
    59  			containers = FlyTable("containers")
    60  			var newCheckContainerHandle string
    61  			for _, container := range containers {
    62  				if container["type"] == "check" {
    63  					newCheckContainerHandle = container["handle"]
    64  					break
    65  				}
    66  			}
    67  			Expect(newCheckContainerHandle).NotTo(Equal(checkContainerHandle))
    68  		})
    69  	})
    70  
    71  	Describe("container for resource checking", func() {
    72  		BeforeEach(func() {
    73  			Deploy("deployments/concourse.yml", "-o", "operations/fast-gc.yml")
    74  		})
    75  
    76  		It("is not immediately removed", func() {
    77  			By("setting pipeline that creates resource config")
    78  			Fly.Run("set-pipeline", "-n", "-c", "pipelines/get-task.yml", "-p", "resource-gc-test")
    79  
    80  			By("unpausing the pipeline")
    81  			Fly.Run("unpause-pipeline", "-p", "resource-gc-test")
    82  
    83  			By("checking resource")
    84  			Fly.Run("check-resource", "-r", "resource-gc-test/tick-tock")
    85  
    86  			Consistently(func() string {
    87  				By("getting the resource config container")
    88  				containers := FlyTable("containers")
    89  				for _, container := range containers {
    90  					if container["type"] == "check" {
    91  						return container["handle"]
    92  					}
    93  				}
    94  
    95  				return ""
    96  			}, 2*time.Minute).ShouldNot(BeEmpty())
    97  		})
    98  
    99  		Context("when two teams use identical configuration", func() {
   100  			var teamName = "A-Team"
   101  
   102  			It("doesn't create many containers for one resource check", func() {
   103  				By("setting pipeline that creates resource config")
   104  				Fly.Run("set-pipeline", "-n", "-c", "pipelines/get-task.yml", "-p", "resource-gc-test")
   105  
   106  				By("unpausing the pipeline")
   107  				Fly.Run("unpause-pipeline", "-p", "resource-gc-test")
   108  
   109  				By("checking resource")
   110  				Fly.Run("check-resource", "-r", "resource-gc-test/tick-tock")
   111  
   112  				By("creating another team")
   113  				Fly.Run("set-team", "--non-interactive", "--team-name", teamName, "--local-user", AtcUsername)
   114  
   115  				Fly.Run("login", "-c", AtcExternalURL, "-n", teamName, "-u", AtcUsername, "-p", AtcPassword)
   116  
   117  				By("setting pipeline that creates an identical resource config")
   118  				Fly.Run("set-pipeline", "-n", "-c", "pipelines/get-task.yml", "-p", "resource-gc-test")
   119  
   120  				By("unpausing the pipeline")
   121  				Fly.Run("unpause-pipeline", "-p", "resource-gc-test")
   122  
   123  				By("checking resource excessively")
   124  				for i := 0; i < 20; i++ {
   125  					Fly.Run("check-resource", "-r", "resource-gc-test/tick-tock")
   126  				}
   127  
   128  				otherTeamCheckCount := len(FlyTable("containers"))
   129  				Expect(otherTeamCheckCount).To(Equal(1))
   130  
   131  				By("checking resource excessively")
   132  				Fly.Run("login", "-c", AtcExternalURL, "-n", "main", "-u", AtcUsername, "-p", AtcPassword)
   133  				for i := 0; i < 20; i++ {
   134  					Fly.Run("check-resource", "-r", "resource-gc-test/tick-tock")
   135  				}
   136  
   137  				mainTeamCheckCount := len(FlyTable("containers"))
   138  				Expect(mainTeamCheckCount).To(Equal(1))
   139  			})
   140  		})
   141  	})
   142  })