Store test reports in build/test-results/ folder#158
Store test reports in build/test-results/ folder#158ycombinator merged 13 commits intoelastic:masterfrom
Conversation
|
AFAIK as I remember I was talking about the |
Oh I see. In that case I totally misunderstood the comment! Yeah, I see the logic in keeping test results out of I can see two ways to implement this:
I'm personally in favor of option 1 because the semantics are pretty intuitive and it results in one less flag (compared to option 2). WDYT? |
I agree with you, unless we follow a different schema:
|
I don't see a concrete use case for I will make the necessary changes to this PR. |
adb0b58 to
f7d6732
Compare
|
The reason why I insisted on keeping results in the side-note: *- maybe we should rethink the |
This is a good discussion! We're having to come up with a general principle to decide what sorts of stuff belongs under I consider
WDYT? |
.ci/Jenkinsfile
Outdated
| post { | ||
| always { | ||
| archiveArtifacts(allowEmptyArchive: true, artifacts: '.elastic-package/tmp/test/reports/*.xml') | ||
| archiveArtifacts(allowEmptyArchive: true, artifacts: '/tmp/build/test-results/*.xml') |
There was a problem hiding this comment.
@mtojek I'm open to using a different absolute path here, if you have a better suggestion.
There was a problem hiding this comment.
I suggest to ask @v1v for suggestion here, but it's fine for me. Maybe you can add a reference to the elastic-package in the middle (e.g. /tmp/elastic-package/build/test-results).
To fully understand the problem - what is the reason you wouldn't like to use the project's internal build directory now? Do you prefer to wait for the result of the discussion around (~/.elastic-package)?
There was a problem hiding this comment.
I'm happy to use the project's internal build directory. I just don't know what the absolute path for it should be in the Jenkins CI environment.
There was a problem hiding this comment.
In my opinion, I'd say everything about the generated files should be within the workspace context, nothing about the HOME but the workspace, then we don't need to worry about cleaning up those leftover files after the build/test but beforehand.
My ideal build process should look like:
$ git clone https://github.com/elastic/elastic-package
$ cd elastic-package
$ make clean check
$ find build/test-results -name *.xml -lsmake clean does remove the build folder if it exists, make check will do as usual but generated test report files will be created in the ./build/test-results folder
.gitignore will help to skip those folders if that's the concern.
There was a problem hiding this comment.
So what is the way to generate the absolute path to the build folder in the workspace context? Specifically, I need to do it over here: https://github.com/elastic/elastic-package/pull/158/files#diff-cdc2dffbf82ed630cddb43c7641dc0534207dd69911283e6fa573efa299f73e6R21.
There was a problem hiding this comment.
|
I think I can add more arguments to the list:
|
scripts/test-check-packages.sh
Outdated
| cd $d | ||
| elastic-package check -v | ||
| elastic-package test -v --report-format xUnit --report-output file | ||
| elastic-package test -v --report-format xUnit --report-output /tmp/build/test-results/ |
There was a problem hiding this comment.
Keep in mind that these tests should be also possible to run using make check locally.
There was a problem hiding this comment.
Good point. I guess we do have a case for a default location (related to the discussion in #158 (comment)). I will revert the recent changes in this PR so the --report-output flag once again takes either stdout or file. And if it's file, it will simply write to the build folder determined by calling FindBuildPackagesDirectory().
There was a problem hiding this comment.
REPORT_FOLDER=$(pwd)/build/test-results/
mkdir -p ${REPORT_FOLDER}
for d in test/packages/*/; do
...
elastic-package test -v --report-format xUnit --report-output "${REPORT_FOLDER}"
There was a problem hiding this comment.
Thanks @v1v.
Chatting with @mtojek about this off-PR I realized that the build directory location is tightly coupled to the elastic-package tool. That is, it's baked in to the tool's code itself and not configurable from the outside. Putting aside whether this is good or bad, for now it makes sense to stay consistent with this model.
As a result I'm going to update this PR again so that --report-output cannot take a path to the build directory. Instead it will take file as a valid value (as it used to before this PR), and if that value is detected, it will write the test results to the build directory that's baked into elastic-package.
13d2aa0 to
bdb4a57
Compare
.ci/Jenkinsfile
Outdated
| always { | ||
| archiveArtifacts(allowEmptyArchive: true, artifacts: '.elastic-package/tmp/test/reports/*.xml') | ||
| sh(label: 'List test results', script: 'pwd && ls -l && ls -l $(pwd)/src/github.com/elastic/elastic-package/build/test-results/') | ||
| archiveArtifacts(allowEmptyArchive: true, artifacts: '$(pwd)/src/github.com/elastic/elastic-package/build/test-results/*.xml') |
There was a problem hiding this comment.
Did you try with dir("${BASE_DIR}") { archiveArtifacts( articats: '<relative path>' ) }?
Similarly to: https://stackoverflow.com/questions/17311369/archive-artifacts-in-jenkins
There was a problem hiding this comment.
I will try this, thanks!
There was a problem hiding this comment.
Looks like my last experiment worked. Turns out I just had a typo in my relative path (build/build instead of just build). So I'm going with it.
c474299 to
8613247
Compare
internal/install/install.go
Outdated
| @@ -92,11 +94,11 @@ func ServiceLogsDir() (string, error) { | |||
|
|
|||
| // TestReportsDir returns the location of the directory to store test reports. | |||
| func TestReportsDir() (string, error) { | |||
There was a problem hiding this comment.
I wonder if TestReportsDir() should be present in install which is related rather to ~/.elastic-package. The test-reports directory won't be in that place anymore.
There was a problem hiding this comment.
Fair point, I'll move it out of that package.
internal/builder/packages.go
Outdated
| if found { | ||
| path := filepath.Join(buildDir, "integrations") // TODO add support for other package types | ||
| fileInfo, err := os.Stat(path) | ||
| if err == nil && fileInfo.IsDir() { |
There was a problem hiding this comment.
nit: maybe refactor this block to two separate if-conditions.
| } | ||
| post { | ||
| always { | ||
| archiveArtifacts(allowEmptyArchive: true, artifacts: '.elastic-package/tmp/test/reports/*.xml') |
There was a problem hiding this comment.
I'd wrap the block into a dir step, so that we capture the base dir (defined in https://github.com/elastic/elastic-package/blob/master/.ci/Jenkinsfile#L8), simplifying the file paths:
always {
dir("${BASE_DIR}"){
archiveArtifacts(allowEmptyArchive: true, artifacts: 'build/test-results/*.xml')
junit(allowEmptyResults: false,
keepLongStdio: true,
testResults: "build/test-results/*.xml")
}
}001b72c to
4e06c37
Compare
|
@mtojek @mdelapenya @v1v This PR is ready for re-review. Thanks! |
mtojek
left a comment
There was a problem hiding this comment.
LGTM!
Are you going to introduce similar changes in https://github.com/elastic/integrations ?
| } | ||
|
|
||
| // testReportsDir returns the location of the directory to store test reports. | ||
| func testReportsDir() (string, error) { |
There was a problem hiding this comment.
Might be a side issue -
Is this directory cleaned up before a next run or does all test results accumulate forever (assume that elastic-package test executes multiple times) ?
There was a problem hiding this comment.
Good question. I'm pretty sure the test results will just accumulate. I'm not sure if that's desired behavior or not. I can see both sides of the argument:
- it's good to let them accumulate because then we have results from previous runs around (and maybe
elastic-package cleanshould clean them out), or - we should clean up each time we run the tests so only the latest results are available at any time.
Obviously, in a CI context this doesn't matter as we will have a fresh environment each time.
Unless you have a preference one way or the other, for now I'm okay with letting them accumulate. If we get feedback about this causing issues, we can address it then. WDYT?
There was a problem hiding this comment.
My thoughts on letting tests accumulate. I haven't seeing this behavior in my past experience in the Java world, where opinionated build systems such as Maven/Gradle define the life cycle. If the report-to-file option is enabled, defaulting to false using standard output, they simply refresh test reports on each test run, redirecting the standard output to the file (I always take a look at how Maven does the thing: http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#redirectTestOutputToFile).
If we do this in another way, I think it could lead to unexpected reports from previous executions in the local machine, although, as you said, in CI this shouldn't be a problem. But I'd prefer having a standard best practice, where the "oracles" (or the behaviours contributors expect -internal and external) are clear.
So I'd go with both approaches: elastic-package clean should clean the test reports, and the test command should start a new file.
There was a problem hiding this comment.
Thanks for these insights, @mdelapenya — much appreciated!
Accordingly, I will update this PR to make the test command clean the test folder so it writes completely new files. We have a separate issue to implement elastic-package clean; I have made a note there: #13 (comment).
Yep, that's the plan (as usual). |
|
@mdelapenya @mtojek I've updated this PR per the feedback in #158 (comment). Please re-review when you get a chance. Thanks! |
|
|
||
| // CleanTestReportsDir removes creates the test reports folder if it already exists, then | ||
| // creates it, effectively resulting in a clean (aka empty) test reports folder. | ||
| func CleanTestReportsDir() error { |
There was a problem hiding this comment.
I'm OK with the logic, although I'd like to know how the reports are generated. If the generation process always writes the reports to the proper place, creating or overwriting the content, then I wonder if the clean one should throw an error (ignoring them if they occur).
Again, my concern is already covered by this PR, so please fee free to merge and discuss in a follow-up not to block it.
Thanks!
There was a problem hiding this comment.
Yeah, let's move forward with this PR and then address any more concerns as they come up when we start using this more.
Co-authored-by: Manuel de la Peña <social.mdelapenya@gmail.com>
Addresses elastic/integrations#315 (comment).
This PR stores test reports generated by
elastic-package test --report-output fileintobuild/test-results/. Before this PR they were being stored in~/.elastic-package/tmp/test/reports/.