Skip to content

Commit de78384

Browse files
feat: [KSBP-101776] - Parallel deployment of test app
1 parent d3711c7 commit de78384

File tree

1 file changed

+45
-45
lines changed

1 file changed

+45
-45
lines changed

k8s-deployer/src/test-suite-handler.ts

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -44,54 +44,11 @@ const deployGraph = async (config: Config, workspace: string, testSuiteId: strin
4444
// Dependencies are already validated in main(), so it's safe to directly sort here.
4545
const { sortedComponents, levels } = topologicalSort(graph.components)
4646

47-
logger.info("")
48-
logger.info("Dependency Resolution for %s:", testSuiteId)
49-
logger.info("Deployment order: %s", sortedComponents.map(c => c.id).join(" → "))
50-
logger.info("")
51-
5247
logger.info("")
5348
logger.info("Dependency Graph for %s:", testSuiteId)
5449
printDependencyGraph(graph.components)
5550
logger.info("")
5651

57-
// Deploy components level by level. Within each level, components with parallel:true are deployed concurrently.
58-
const deployments: Array<DeployedComponent> = []
59-
let componentIndex = 0
60-
for (const level of levels) {
61-
const parallelGroup = level.filter(c => c.parallel === true)
62-
const sequentialGroup = level.filter(c => c.parallel !== true)
63-
64-
// Deploy all parallel-flagged components in this level concurrently
65-
if (parallelGroup.length > 0) {
66-
logger.info("")
67-
logger.info("Deploying %d component(s) in parallel for suite \"%s\": %s", parallelGroup.length, testSuiteId, parallelGroup.map(c => c.id).join(", "))
68-
const parallelResults = await Promise.all(
69-
parallelGroup.map(async componentSpec => {
70-
const idx = ++componentIndex
71-
logger.info("Deploying graph component (%s of %s) \"%s\" for suite \"%s\"...", idx, sortedComponents.length, componentSpec.name, testSuiteId)
72-
const commitSha = await Deployer.deployComponent(config, workspace, componentSpec, namespace)
73-
logger.info("Graph component \"%s\" for suite \"%s\" deployed.", componentSpec.name, testSuiteId)
74-
return new DeployedComponent(commitSha, componentSpec)
75-
})
76-
)
77-
deployments.push(...parallelResults)
78-
}
79-
80-
// Deploy sequential components one by one
81-
for (const componentSpec of sequentialGroup) {
82-
const idx = ++componentIndex
83-
logger.info("")
84-
logger.info("Deploying graph component (%s of %s) \"%s\" for suite \"%s\"...", idx, sortedComponents.length, componentSpec.name, testSuiteId)
85-
logger.info("")
86-
const commitSha = await Deployer.deployComponent(config, workspace, componentSpec, namespace)
87-
deployments.push(new DeployedComponent(commitSha, componentSpec))
88-
}
89-
}
90-
logger.info("")
91-
92-
logger.info("%s Deploying test app \"%s\" for suite \"%s\" %s", LOG_SEPARATOR_LINE, graph.testApp.name, testSuiteId, LOG_SEPARATOR_LINE)
93-
logger.info("")
94-
9552
if (testAppDirForRemoteTestSuite) {
9653
// When suite is remote its pitfile is sitting within test app itself.
9754
// We just downloaded pitfile from remote location into workspace
@@ -101,10 +58,53 @@ const deployGraph = async (config: Config, workspace: string, testSuiteId: strin
10158
)
10259
graph.testApp.location.path = testAppDirForRemoteTestSuite
10360
}
61+
62+
// Deploy components level by level. Within each level, components with parallel:true are deployed concurrently.
63+
const deployments: Array<DeployedComponent> = []
64+
let componentIndex = 0
65+
const deployComponentsPromise = (async () => {
66+
for (const level of levels) {
67+
const parallelGroup = level.filter(c => c.parallel === true)
68+
const sequentialGroup = level.filter(c => c.parallel !== true)
69+
70+
// Deploy all parallel-flagged components in this level concurrently
71+
if (parallelGroup.length > 0) {
72+
logger.info("")
73+
logger.info("Deploying %d component(s) in parallel for suite \"%s\": %s", parallelGroup.length, testSuiteId, parallelGroup.map(c => c.id).join(", "))
74+
const parallelResults = await Promise.all(
75+
parallelGroup.map(async componentSpec => {
76+
const idx = ++componentIndex
77+
logger.info("Deploying graph component (%s of %s) \"%s\" for suite \"%s\"...", idx, sortedComponents.length, componentSpec.name, testSuiteId)
78+
const commitSha = await Deployer.deployComponent(config, workspace, componentSpec, namespace)
79+
logger.info("Graph component \"%s\" for suite \"%s\" deployed.", componentSpec.name, testSuiteId)
80+
return new DeployedComponent(commitSha, componentSpec)
81+
})
82+
)
83+
deployments.push(...parallelResults)
84+
}
85+
86+
// Deploy sequential components one by one
87+
for (const componentSpec of sequentialGroup) {
88+
const idx = ++componentIndex
89+
logger.info("")
90+
logger.info("Deploying graph component (%s of %s) \"%s\" for suite \"%s\"...", idx, sortedComponents.length, componentSpec.name, testSuiteId)
91+
logger.info("")
92+
const commitSha = await Deployer.deployComponent(config, workspace, componentSpec, namespace)
93+
deployments.push(new DeployedComponent(commitSha, componentSpec))
94+
}
95+
}
96+
})()
97+
98+
// Deploy test app concurrently with the component levels; deployGraph does not return until both are done.
99+
logger.info("%s Deploying test app \"%s\" for suite \"%s\" %s", LOG_SEPARATOR_LINE, graph.testApp.name, testSuiteId, LOG_SEPARATOR_LINE)
104100
const params = [ testSuiteId ]
105-
const testAppCommitSha = await Deployer.deployComponent(config, workspace, graph.testApp, namespace, params)
101+
const deployTestAppPromise = Deployer.deployComponent(config, workspace, graph.testApp, namespace, params)
102+
.then(commitSha => new DeployedComponent(commitSha, graph.testApp))
103+
104+
const [ , testAppDeployedComponent] = await Promise.all([deployComponentsPromise, deployTestAppPromise])
105+
106106
logger.info("")
107-
return new GraphDeploymentResult(deployments, new DeployedComponent(testAppCommitSha, graph.testApp))
107+
return new GraphDeploymentResult(deployments, testAppDeployedComponent)
108108
}
109109

110110
const downloadPitFile = async (testSuite: Schema.TestSuite, destination: string): Promise<Schema.PitFile> => {

0 commit comments

Comments
 (0)