-
Notifications
You must be signed in to change notification settings - Fork 54
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
Adding system tests #399
base: dev_main
Are you sure you want to change the base?
Adding system tests #399
Conversation
* Delete unnecessary tests * Move some tests into 'systemTests' folder
<!-- Dependencies for system tests --> | ||
<!-- https://mvnrepository.com/artifact/com.jcabi/jcabi-xml --> | ||
<dependency> | ||
<groupId>com.jcabi</groupId> | ||
<artifactId>jcabi-xml</artifactId> | ||
<version>0.23.1</version> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/org.jenkinsci.plugins/pipeline-model-definition --> | ||
<dependency> | ||
<groupId>org.jenkinsci.plugins</groupId> | ||
<artifactId>pipeline-model-definition</artifactId> | ||
</dependency> | ||
<!-- Need unzip to add the files in pipeline workspace --> | ||
<!-- https://mvnrepository.com/artifact/org.jenkins-ci.plugins/pipeline-utility-steps --> | ||
<dependency> | ||
<groupId>org.jenkins-ci.plugins</groupId> | ||
<artifactId>pipeline-utility-steps</artifactId> | ||
<version>2.7.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- TODO: see if this is necessary Using for verifyCodeCoverage --> | ||
<!-- https://mvnrepository.com/artifact/org.jenkins-ci.plugins/cobertura --> | ||
<dependency> | ||
<groupId>org.jenkins-ci.plugins</groupId> | ||
<artifactId>cobertura</artifactId> | ||
<version>1.16</version> | ||
</dependency> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the pipeline-utility-steps
dependency uses the test scope (<scope>test</scope>
), can all of them use test scope?
@@ -1,136 +1,136 @@ | |||
package unit.com.mathworks.ci.actions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never noticed this before but we have separate test packages. In the Bamboo plugin we use the same package. Should the package be updated or are we going to keep them in separate packages?
@@ -0,0 +1,28 @@ | |||
name: using mpm to install MATLAB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that we're using GitHub Actions. Does this mean we can remove the Azure Pipelines yaml?
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Java 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '11' | ||
distribution: 'temurin' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider updating to actions/checkout@v4
and actions/setup-java@v4
Also consider adding the cache: maven
option to the setup-java
step as shown here. It could improve build times by quite a bit.
String matlabRoot = System.getenv("MATLAB_ROOT"); | ||
Assume.assumeTrue("Not running tests as MATLAB_ROOT environment variable is not defined", matlabRoot != null && !matlabRoot.isEmpty()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is MATLAB_ROOT
getting set by our Jenkins plugin? It doesn't seem like this would be set before the test class is run.
String matlabRoot = System.getenv("MATLAB_ROOT"); | ||
String matlabRoot22b = System.getenv("MATLAB_ROOT_22b"); | ||
Assume.assumeTrue("Not running tests as MATLAB_ROOT_22b environment variable is not defined", matlabRoot22b != null && !matlabRoot22b.isEmpty()); | ||
|
||
Utilities.setMatlabInstallation("MATLAB_PATH_1", matlabRoot, jenkins); | ||
Utilities.setMatlabInstallation("MATLAB_PATH_2", matlabRoot22b, jenkins); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question here. What's setting MATLAB_ROOT_22b
environment variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really good! Definitely a huge improvement, just a couple of things that I caught during the review.
name: using mpm to install MATLAB | ||
on: push | ||
jobs: | ||
my-job: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could maybe give this job a more descriptive name in case we want to add more in the future.
private UseMatlabVersionBuildWrapper buildWrapper; | ||
|
||
@Rule | ||
public Timeout timeout = Timeout.seconds(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Timing out after 0 seconds seems pretty quick to me, was that intentional?
Utilities.setMatlabInstallation("MATLAB_PATH", Utilities.getMatlabRoot(), jenkins); | ||
|
||
// Selecting MATLAB that is defined as Global tool | ||
MatlabInstallation _inst = MatlabInstallation.getInstallation("MATLAB_PATH"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I normally think of variables names starting with an _
as values that are going to be thrown away or not referenced later. Maybe we should just call that variable inst
?
|
||
jenkins.assertLogContains(_inst.getHome(), build); | ||
jenkins.assertBuildStatus(Result.SUCCESS, build); | ||
jenkins.assertLogContains("apple", build); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we still print out the contents of the script that we're generating, so checking for apple
in the build log might not indicate that the command actually ran. It could just indicate that a script with those contents were generated.
FreeStyleBuild build = project.scheduleBuild2(0).get(); | ||
|
||
jenkins.assertBuildStatus(Result.FAILURE, build); | ||
jenkins.assertLogContains("Verify global tool configuration for the specified node.", build); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could fail in a future Jenkins update, which is just something that we should be aware of in case it ever shows up.
@Test | ||
public void verifyMATLABscratchFileNotGenerated() throws Exception { | ||
this.buildWrapper.setMatlabBuildWrapperContent( | ||
new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), Utilities.getMatlabRoot())); | ||
project.getBuildWrappersList().add(this.buildWrapper); | ||
scriptBuilder.setTasks(""); | ||
project.getBuildersList().add(this.scriptBuilder); | ||
FreeStyleBuild build = project.scheduleBuild2(0).get(); | ||
File matlabRunner = new File(build.getWorkspace() + File.separator + "runMatlabTests.m"); | ||
Assert.assertFalse(matlabRunner.exists()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this test case is probably not necessry.
RunMatlabBuildBuilder tester = | ||
new RunMatlabBuildBuilder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
RunMatlabBuildBuilder tester = | ||
new RunMatlabBuildBuilder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
runTestsStep.setStartupOptions(new StartupOptions("-logfile outputTests.log")); | ||
project.getBuildersList().add(runTestsStep); | ||
|
||
//Rub Build step |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//Rub Build step | |
// Run Build step |
// ToDo: Figure out how to run these tests where MATLAB needs to be unaccesible locally and in CI/CD | ||
|
||
// @Test | ||
// public void verifyEmptyRootError() throws Exception { | ||
// String script = "pipeline {\n" + | ||
// " agent any\n" + | ||
// " stages{\n" + | ||
// " stage('Run MATLAB Command') {\n" + | ||
// " steps\n" + | ||
// " {\n" + | ||
// " runMATLABCommand 'version' \n" + | ||
// " }\n" + | ||
// " }\n" + | ||
// " }\n" + | ||
// "}"; | ||
// WorkflowJob project = jenkins.createProject(WorkflowJob.class); | ||
// project.setDefinition(new CpsFlowDefinition(script, true)); | ||
// WorkflowRun build = project.scheduleBuild2(0).get(); | ||
// | ||
// jenkins.assertLogContains("MATLAB_ROOT",build); | ||
// jenkins.assertBuildStatus(Result.FAILURE,build); | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment left in
This PR has following changes:
System tests needs access to MATLAB to run successfully. The MATLAB root path is read from 'MATLAB_ROOT' env variable. These tests are configured to run only if the 'MATLAB_ROOT' variable is defined. This is to ensure that the tests pass in Jenkinsci jobs and it makes it easier to run the tests locally as well.
Matrix project needs two versions of MATLAB to run successfully. Since there is an error while using Set up MATLAB twice, these tests would be skipped(Updating the main.yml to define MATLAB_ROOT_22b would trigger the tests)
System tests follow the standard integration tests format *IT.java. These tests can be run in isolation using failsafe plugin.
mvn test - Runs only unit tests
mvn verify - Runs both unit and system tests
mvn failsafe:integration-test - Runs only system tests