From df16dca824560ad6ca1ec2164992ad241b60d86a Mon Sep 17 00:00:00 2001 From: Sarah French Date: Tue, 19 Mar 2024 23:52:25 +0100 Subject: [PATCH 1/3] Make service sweepers run before project sweepers, assert that in a test --- .../projects/reused/nightly_tests.kt | 2 +- .../terraform/.teamcity/tests/sweepers.kt | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/mmv1/third_party/terraform/.teamcity/components/projects/reused/nightly_tests.kt b/mmv1/third_party/terraform/.teamcity/components/projects/reused/nightly_tests.kt index cb6455e5f752..75fd33a9d529 100644 --- a/mmv1/third_party/terraform/.teamcity/components/projects/reused/nightly_tests.kt +++ b/mmv1/third_party/terraform/.teamcity/components/projects/reused/nightly_tests.kt @@ -51,7 +51,7 @@ fun nightlyTests(parentProject:String, providerName: String, vcsRoot: GitVcsRoot else -> throw Exception("Provider name not supplied when generating a nightly test subproject") } val serviceSweeperConfig = BuildConfigurationForServiceSweeper(providerName, ServiceSweeperName, sweepersList, projectId, vcsRoot, sharedResources, config) - val sweeperTrigger = NightlyTriggerConfiguration(startHour=12) // Override hour + val sweeperTrigger = NightlyTriggerConfiguration(startHour=11) // Override hour serviceSweeperConfig.addTrigger(sweeperTrigger) return Project { diff --git a/mmv1/third_party/terraform/.teamcity/tests/sweepers.kt b/mmv1/third_party/terraform/.teamcity/tests/sweepers.kt index 67940004bc68..d6805843a39c 100644 --- a/mmv1/third_party/terraform/.teamcity/tests/sweepers.kt +++ b/mmv1/third_party/terraform/.teamcity/tests/sweepers.kt @@ -7,12 +7,14 @@ package tests +import ProjectSweeperName import ServiceSweeperName import jetbrains.buildServer.configs.kotlin.BuildType import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test import jetbrains.buildServer.configs.kotlin.Project +import jetbrains.buildServer.configs.kotlin.triggers.ScheduleTrigger import org.junit.Assert import projects.googleCloudRootProject @@ -102,4 +104,50 @@ class SweeperTests { val value = sweeper!!.params.findRawParam("PACKAGE_PATH")!!.value assertEquals("./google-beta/sweeper", value) } + + @Test + fun projectSweepersRunAfterServiceSweepers() { + val project = googleCloudRootProject(testContextParameters()) + + // Find GA nightly test project's service sweeper + val gaNightlyTestProject = getSubProject(project, gaProjectName, nightlyTestsProjectName) + val sweeperGa: BuildType? = gaNightlyTestProject!!.buildTypes.find { p-> p.name == ServiceSweeperName} + if (sweeperGa == null) { + Assert.fail("Could not find the sweeper build in the Google (GA) Nightly Test project") + } + + // Find Beta nightly test project's service sweeper + val betaNightlyTestProject = getSubProject(project, betaProjectName, nightlyTestsProjectName) + val sweeperBeta: BuildType? = betaNightlyTestProject!!.buildTypes.find { p-> p.name == ServiceSweeperName} + if (sweeperBeta == null) { + Assert.fail("Could not find the sweeper build in the Google (Beta) Nightly Test project") + } + + // Find Project sweeper project's build + val projectSweeperProject: Project? = project.subProjects.find { p-> p.name == projectSweeperProjectName} + if (projectSweeperProject == null) { + Assert.fail("Could not find the Project Sweeper project") + } + val projectSweeper: BuildType? = projectSweeperProject!!.buildTypes.find { p-> p.name == ProjectSweeperName} + if (projectSweeper == null) { + Assert.fail("Could not find the sweeper build in the Google (Beta) Nightly Test project") + } + + + // Check only one schedule trigger is on the builds in question + assertTrue(sweeperGa!!.triggers.items.size == 1) + assertTrue(sweeperBeta!!.triggers.items.size == 1) + assertTrue(projectSweeper!!.triggers.items.size == 1) + + // Assert that the hour value that sweeper builds are triggered at is less than the hour value that project sweeper builds are triggered at + // i.e. sweeper builds are triggered first + val stGa = sweeperGa!!.triggers.items[0] as ScheduleTrigger + val cronGa = stGa.schedulingPolicy as ScheduleTrigger.SchedulingPolicy.Cron + val stBeta = sweeperBeta!!.triggers.items[0] as ScheduleTrigger + val cronBeta = stBeta.schedulingPolicy as ScheduleTrigger.SchedulingPolicy.Cron + val stProject = projectSweeper!!.triggers.items[0] as ScheduleTrigger + val cronProject = stProject.schedulingPolicy as ScheduleTrigger.SchedulingPolicy.Cron + assertTrue("Service sweeper for the GA Nightly Test project is triggered at an earlier hour than the project sweeper", cronGa.hours.toString() < cronProject.hours.toString()) // Values are strings like "11", "12" + assertTrue("Service sweeper for the Beta Nightly Test project is triggered at an earlier hour than the project sweeper", cronBeta.hours.toString() < cronProject.hours.toString() ) + } } From 897647ac07c458bd4678080622be23d25dfb6123 Mon Sep 17 00:00:00 2001 From: Sarah French Date: Wed, 20 Mar 2024 00:04:13 +0100 Subject: [PATCH 2/3] Add reusible test util that pulls a given build from a project, refactor test --- .../terraform/.teamcity/tests/sweepers.kt | 24 ++++++------------- .../terraform/.teamcity/tests/test_utils.kt | 15 ++++++++++-- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/mmv1/third_party/terraform/.teamcity/tests/sweepers.kt b/mmv1/third_party/terraform/.teamcity/tests/sweepers.kt index d6805843a39c..b0a05dd1f322 100644 --- a/mmv1/third_party/terraform/.teamcity/tests/sweepers.kt +++ b/mmv1/third_party/terraform/.teamcity/tests/sweepers.kt @@ -110,30 +110,20 @@ class SweeperTests { val project = googleCloudRootProject(testContextParameters()) // Find GA nightly test project's service sweeper - val gaNightlyTestProject = getSubProject(project, gaProjectName, nightlyTestsProjectName) - val sweeperGa: BuildType? = gaNightlyTestProject!!.buildTypes.find { p-> p.name == ServiceSweeperName} - if (sweeperGa == null) { - Assert.fail("Could not find the sweeper build in the Google (GA) Nightly Test project") - } + val gaNightlyTests: Project = getSubProject(project, gaProjectName, nightlyTestsProjectName) + val sweeperGa: BuildType = getBuildFromProject(gaNightlyTests, ServiceSweeperName) // Find Beta nightly test project's service sweeper - val betaNightlyTestProject = getSubProject(project, betaProjectName, nightlyTestsProjectName) - val sweeperBeta: BuildType? = betaNightlyTestProject!!.buildTypes.find { p-> p.name == ServiceSweeperName} - if (sweeperBeta == null) { - Assert.fail("Could not find the sweeper build in the Google (Beta) Nightly Test project") - } + val betaNightlyTests : Project = getSubProject(project, betaProjectName, nightlyTestsProjectName) + val sweeperBeta: BuildType = getBuildFromProject(betaNightlyTests, ServiceSweeperName) // Find Project sweeper project's build - val projectSweeperProject: Project? = project.subProjects.find { p-> p.name == projectSweeperProjectName} + val projectSweeperProject : Project? = project.subProjects.find { p-> p.name == projectSweeperProjectName} if (projectSweeperProject == null) { Assert.fail("Could not find the Project Sweeper project") } - val projectSweeper: BuildType? = projectSweeperProject!!.buildTypes.find { p-> p.name == ProjectSweeperName} - if (projectSweeper == null) { - Assert.fail("Could not find the sweeper build in the Google (Beta) Nightly Test project") - } - - + val projectSweeper: BuildType = getBuildFromProject(projectSweeperProject!!, ProjectSweeperName) + // Check only one schedule trigger is on the builds in question assertTrue(sweeperGa!!.triggers.items.size == 1) assertTrue(sweeperBeta!!.triggers.items.size == 1) diff --git a/mmv1/third_party/terraform/.teamcity/tests/test_utils.kt b/mmv1/third_party/terraform/.teamcity/tests/test_utils.kt index 162a38eccf5c..04ba0e7c8d05 100644 --- a/mmv1/third_party/terraform/.teamcity/tests/test_utils.kt +++ b/mmv1/third_party/terraform/.teamcity/tests/test_utils.kt @@ -8,6 +8,8 @@ package tests import builds.AllContextParameters +import jetbrains.buildServer.BuildProject +import jetbrains.buildServer.configs.kotlin.BuildType import jetbrains.buildServer.configs.kotlin.Project import org.junit.Assert @@ -56,15 +58,24 @@ fun testContextParameters(): AllContextParameters { fun getSubProject(rootProject: Project, parentProjectName: String, subProjectName: String): Project { // Find parent project within root - var parentProject: Project? = rootProject.subProjects.find { p-> p.name == parentProjectName} + val parentProject: Project? = rootProject.subProjects.find { p-> p.name == parentProjectName} if (parentProject == null) { Assert.fail("Could not find the $parentProjectName project") } // Find subproject within parent identified above - var subProject: Project? = parentProject!!.subProjects.find { p-> p.name == subProjectName} + val subProject: Project? = parentProject!!.subProjects.find { p-> p.name == subProjectName} if (subProject == null) { Assert.fail("Could not find the $subProjectName project") } return subProject!! +} + +fun getBuildFromProject(parentProject: Project, buildName: String): BuildType { + val buildType: BuildType? = parentProject!!.buildTypes.find { p-> p.name == buildName} + if (buildType == null) { + Assert.fail("Could not find the '$buildName' build in project ${parentProject.name}") + } + + return buildType!! } \ No newline at end of file From 8aac487cc17d076b47b692079e775da589a8cb2c Mon Sep 17 00:00:00 2001 From: Sarah French Date: Thu, 21 Mar 2024 15:26:59 +0100 Subject: [PATCH 3/3] Remove unneeded `!!` --- .../terraform/.teamcity/tests/sweepers.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mmv1/third_party/terraform/.teamcity/tests/sweepers.kt b/mmv1/third_party/terraform/.teamcity/tests/sweepers.kt index b0a05dd1f322..34f9dfd2c5a8 100644 --- a/mmv1/third_party/terraform/.teamcity/tests/sweepers.kt +++ b/mmv1/third_party/terraform/.teamcity/tests/sweepers.kt @@ -125,17 +125,17 @@ class SweeperTests { val projectSweeper: BuildType = getBuildFromProject(projectSweeperProject!!, ProjectSweeperName) // Check only one schedule trigger is on the builds in question - assertTrue(sweeperGa!!.triggers.items.size == 1) - assertTrue(sweeperBeta!!.triggers.items.size == 1) - assertTrue(projectSweeper!!.triggers.items.size == 1) + assertTrue(sweeperGa.triggers.items.size == 1) + assertTrue(sweeperBeta.triggers.items.size == 1) + assertTrue(projectSweeper.triggers.items.size == 1) // Assert that the hour value that sweeper builds are triggered at is less than the hour value that project sweeper builds are triggered at // i.e. sweeper builds are triggered first - val stGa = sweeperGa!!.triggers.items[0] as ScheduleTrigger + val stGa = sweeperGa.triggers.items[0] as ScheduleTrigger val cronGa = stGa.schedulingPolicy as ScheduleTrigger.SchedulingPolicy.Cron - val stBeta = sweeperBeta!!.triggers.items[0] as ScheduleTrigger + val stBeta = sweeperBeta.triggers.items[0] as ScheduleTrigger val cronBeta = stBeta.schedulingPolicy as ScheduleTrigger.SchedulingPolicy.Cron - val stProject = projectSweeper!!.triggers.items[0] as ScheduleTrigger + val stProject = projectSweeper.triggers.items[0] as ScheduleTrigger val cronProject = stProject.schedulingPolicy as ScheduleTrigger.SchedulingPolicy.Cron assertTrue("Service sweeper for the GA Nightly Test project is triggered at an earlier hour than the project sweeper", cronGa.hours.toString() < cronProject.hours.toString()) // Values are strings like "11", "12" assertTrue("Service sweeper for the Beta Nightly Test project is triggered at an earlier hour than the project sweeper", cronBeta.hours.toString() < cronProject.hours.toString() )