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

Adding system tests #399

Open
wants to merge 24 commits into
base: dev_main
Choose a base branch
from
Open

Adding system tests #399

wants to merge 24 commits into from

Conversation

Vahila
Copy link
Member

@Vahila Vahila commented Jan 20, 2025

This PR has following changes:

  • Added system tests under src/test/java/com/mathworks/ci/systemTests
  • Moved the integ test under the above mentioned folder as sometimes there are errors because of inconsistent directory and package path
  • Deleted some unnecessary tests

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

@Vahila Vahila marked this pull request as ready for review January 20, 2025 16:18
Comment on lines +129 to +155
<!-- 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>
Copy link
Member

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;
Copy link
Member

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
Copy link
Member

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?

Comment on lines +10 to +19
steps:
- name: Check out repository
uses: actions/checkout@v2

- name: Setup Java 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'

Copy link
Member

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.

Comment on lines +43 to +44
String matlabRoot = System.getenv("MATLAB_ROOT");
Assume.assumeTrue("Not running tests as MATLAB_ROOT environment variable is not defined", matlabRoot != null && !matlabRoot.isEmpty());
Copy link
Member

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.

Comment on lines +106 to +111
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);
Copy link
Member

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?

Copy link
Member

@sameagen-MW sameagen-MW left a 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:
Copy link
Member

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);
Copy link
Member

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");
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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.

Comment on lines +171 to +181
@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());
}
Copy link
Member

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.

Comment on lines +207 to +208
RunMatlabBuildBuilder tester =
new RunMatlabBuildBuilder();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

Comment on lines +229 to +230
RunMatlabBuildBuilder tester =
new RunMatlabBuildBuilder();
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//Rub Build step
// Run Build step

Comment on lines +101 to +122
// 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);
// }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment left in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants