Skip to content

Commit

Permalink
Make service sweepers run before project sweepers, assert that in a test
Browse files Browse the repository at this point in the history
  • Loading branch information
SarahFrench committed Mar 19, 2024
1 parent 5fddaec commit 37d5287
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
48 changes: 48 additions & 0 deletions mmv1/third_party/terraform/.teamcity/tests/sweepers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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() )
}
}

0 comments on commit 37d5287

Please sign in to comment.