Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handling of Unit tests in D and DevPreview #827

Merged
merged 8 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
- RM: test component causes new jenkins (run) instance after branch is created for release
([#823](https://github.com/opendevstack/ods-jenkins-shared-library/issues/823))
- Improve error message when two coded tests are linked to the same test issue ([#826](https://github.com/opendevstack/ods-jenkins-shared-library/pull/826))
- Better handling of Unit tests in D and DevPreview ([827](https://github.com/opendevstack/ods-jenkins-shared-library/pull/827))
- Fix RM: *found unexecuted Jira tests* error during promote2Production when functional test only runs on D and QA ([#832](https://github.com/opendevstack/ods-jenkins-shared-library/pull/832))

## [3.0] - 2020-08-11
Expand Down
11 changes: 7 additions & 4 deletions src/org/ods/orchestration/BuildStage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class BuildStage extends Stage {
Closure executeRepos = {
util.prepareExecutePhaseForReposNamedJob(phase, repos, preExecuteRepo, postExecuteRepo)
.each { group ->
group.failFast = true
// FailFast only if not WIP
group.failFast = !project.isWorkInProgress
script.parallel(group)
}
}
Expand All @@ -88,11 +89,13 @@ class BuildStage extends Stage {
// - this will only apply in case of WIP! - otherwise failfast is configured, and hence
// the build will have failed beforehand
def failedRepos = repos.flatten().findAll { it.data?.failedStage }
if (project.isAssembleMode && project.isWorkInProgress &&
(project.hasFailingTests() || failedRepos.size > 0)) {
if (project.hasFailingTests() || failedRepos.size > 0) {
def errMessage = "Failing build as repositories contain errors!\nFailed: ${failedRepos}"
util.failBuild(errMessage)
throw new IllegalStateException(errMessage)
// If we are not in Developer Preview raise a exception
if (!project.isWorkInProgress) {
throw new IllegalStateException(errMessage)
}
}
}

Expand Down
91 changes: 91 additions & 0 deletions test/groovy/org/ods/orchestration/BuildStageSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package org.ods.orchestration

import org.ods.PipelineScript
import org.ods.orchestration.scheduler.LeVADocumentScheduler
import org.ods.orchestration.usecase.JiraUseCase
import org.ods.orchestration.util.MROPipelineUtil
import org.ods.orchestration.util.Project
import org.ods.services.ServiceRegistry
import org.ods.util.ILogger
import org.ods.util.IPipelineSteps
import org.ods.util.Logger
import org.ods.util.PipelineSteps
import util.SpecHelper

import static util.FixtureHelper.createProject

class BuildStageSpec extends SpecHelper {
Project project
BuildStage buildStage
IPipelineSteps steps
PipelineScript script
MROPipelineUtil util
JiraUseCase jira
LeVADocumentScheduler levaDocScheduler
ILogger logger

def phase = MROPipelineUtil.PipelinePhases.BUILD

def setup() {
script = new PipelineScript()
steps = Mock(PipelineSteps)
levaDocScheduler = Mock(LeVADocumentScheduler)
project = Spy(createProject())
util = Mock(MROPipelineUtil)
jira = Mock(JiraUseCase)
logger = new Logger(script, true)
createService()
buildStage = Spy(new BuildStage(script, project, project.repositories, null))
}

ServiceRegistry createService() {
def registry = ServiceRegistry.instance

registry.add(PipelineSteps, steps)
registry.add(LeVADocumentScheduler, levaDocScheduler)
registry.add(MROPipelineUtil, util)
registry.add(JiraUseCase, jira)
registry.add(Logger, logger)

return registry
}

def "successful execution"() {
when:
buildStage.run()

then:
1 * levaDocScheduler.run(phase, MROPipelineUtil.PipelinePhaseLifecycleStage.POST_START)
1 * levaDocScheduler.run(phase, MROPipelineUtil.PipelinePhaseLifecycleStage.PRE_END)
}

def "unit test errors in WIP version doesn't break the stage"() {
given:
project.hasFailingTests = true
project.data.buildParams.version = project.BUILD_PARAM_VERSION_DEFAULT

when:
buildStage.run()

then:
1 * levaDocScheduler.run(phase, MROPipelineUtil.PipelinePhaseLifecycleStage.POST_START)
1 * levaDocScheduler.run(phase, MROPipelineUtil.PipelinePhaseLifecycleStage.PRE_END)
1 * util.failBuild(_)
}

def "unit test errors in X version break the stage"() {
given:
project.hasFailingTests = true

when:
buildStage.run()

then:
1 * levaDocScheduler.run(phase, MROPipelineUtil.PipelinePhaseLifecycleStage.POST_START)
1 * levaDocScheduler.run(phase, MROPipelineUtil.PipelinePhaseLifecycleStage.PRE_END)
1 * util.failBuild(_)
IllegalStateException ex = thrown()
ex.message == 'Failing build as repositories contain errors!\nFailed: []'
}

}