odpi / egeria

Egeria core
https://egeria-project.org
Apache License 2.0
806 stars 260 forks source link

Automate the FVT tests #426

Closed davidradl closed 4 years ago

davidradl commented 5 years ago

use a container approach similar to what is proposed for the proposed Conformance test automation

planetf1 commented 5 years ago

We should look at automating the deployment of a k8s environment based on egeria that we can run automated tests against, configured from within the build pipeline

First step:

planetf1 commented 4 years ago

Results of fvt test runs should be stored as some kind of build output artifact so that it can be referred to both by developers (to see how the last test run went) and for consuming organisations wanting to see the results from the current release.

planetf1 commented 4 years ago

Looking at what we have under FVT currently:

One we have a deployed environment and pipeline we can return and link these with the runtime

planetf1 commented 4 years ago

In #3245 we had some confusion over which tests to run, and in #3254 around the environment.

It's excellent we have some FVT tests, it's clear a little time invested in running these tests automatically (ie via surefire) with the likely needed refactoring will pay off, and we can extend the model to other tests.

I think this will supercede #747 so will close that

Aiming to 2.1 timeframe.

planetf1 commented 4 years ago

Our current unit tests use the 'surefire' plugin. If a test failure occurs the build immediately aborts. Whilst the surefire plugin could be used to execute any kind of test, it's not well suited to having pre and post environment setup steps prior to the actual test. For example launching the egeria chassis or tearing it down.

Failsafe (an anagram of surefire) allows this, and the maven faq positions failsafe as more appropriate for integration testing. https://maven.apache.org/surefire/maven-failsafe-plugin/ https://www.baeldung.com/maven-failsafe-plugin https://stackoverflow.com/questions/28986005/what-is-the-difference-between-the-maven-surefire-and-maven-failsafe-plugins

It can still run junit, testng, pojo etc tests , and just as with surefire, coverage data can be captured to be used with Jacoco & potentially onwards to sonar.

Therefore I am proposing we gear functional tests around failsafe. These will be tests that require some running components to execute - so are more complex and may take longer than unit tests.

Tests will not be run by default (mvn clean install) but will be run with 'mvn verify' . This can be added to the merge build, but most likely not the PR build due to time taken (we can check and add after if wanted).

failsafe's convention is that tests are named: "/IT*.java" - includes all of its subdirectories and all Java filenames that start with "IT". "*/IT.java" - includes all of its subdirectories and all Java filenames that end with "IT". "/*ITCase.java"

Additionally the plugin looks for these files under src/test/java

These can be overridden - see http://maven.apache.org/surefire/maven-failsafe-plugin/examples/inclusion-exclusion.html , though it would be preferable to keep to these convensions -- especially for new tests -- to aid code clarity by adhering to convention.

This brings us to the current Subject Area FVTs and how they might be integrated. Currently they are in a standalone project under open-metadata-test/open-metadata-fvt

Egeria is a multi-module maven project. When we run 'mvn install' for example, maven figures out a dependency order, and then executes to the install lifecycle phase in each module in turn. If we go for 'mvn verify' then it will do the same up to the verify lifecycle stage. So it does not do every project's 'clean' then 'prepare' then 'compile' etc.

This means we need to be careful with where Integration tests go. If they are truly dependent on the entire chassis we must ensure we depend on that component. Or indeed if we need to use the assemblies to run egeria we must depend on that (as long as the assemblies don't need to then pick up test results or similar... causing a circular dependency ....). Starting with a clean high level tree which is easier to make dependent on everything else (like the assembly) seems like the way to start. Of course this gives us a maven module with no source - something maven central will object to....

Also Each suite of tests (in a directory) is independent -- unfortunately this means any pre/post steps - which could include starting a server are done for each suite. This could be slow.

It seems as if maven isn't ideally suited and we are pushing the boundaries...

My proposal is therefore

I'll work on the basis of creating a PR, we can discuss during the process/at review status if we need to make a change of direction

Subsequent work could

There are also more complex test automation needed around deploying to k8s, testing a full coco pharma environment, perhaps browser testing with selenium or similar -- and this likely goes way outside maven's sweet spot, so this is just a first step to improve our test coverage/execution Any comments? cc: @davidradl

planetf1 commented 4 years ago

A little more evaluation of various options & some experimentation of a few techniques:

planetf1 commented 4 years ago

A quick update on status

planetf1 commented 4 years ago

I've now created a PR #3297 with the first running version. The PR has extensive notes on what it does & limitations.

In terms of general discussion ... I was not able to get failsafe to run POJO tests reliably. Many approaches were tried. Specifically the problem was in failsafe identifying which classes and methods to use. In theory this should work, and in discussion on the mailing lists I tried a test project which worked ok, but I was unable to translate this into egeria. Even then I'd need to create a new POJO method to run the test easily without parms (but with the parms I needed)

The 'natural' approach for failsafe is to use a test framework like JUnit5, and to have tests defined in 'src/test/' By switching to this model tests were found reliably . The current FVTs were not written as JUnits, so the first pass was to add a wrapper test method to demonstrate the approach - though as the PR notes, more work is needed on at a minimum ensuring errors are correctly returned.

For further tests I think the idea of having an integration test directory distinct from the rest of the code is sound, but we should use the test directories, and write as JUnit(5)s. I suggest we take a another batch of tests to apply that approach to, and in the process can consider adding docs & refactoring poms etc to reduce duplication when adding new FVTs.

planetf1 commented 4 years ago

The first step of this has been done.

Any specific changes for subject area can be covered in a subject area specific issue

Next steps

planetf1 commented 4 years ago

FVTs running in merge build perfectly, so the approach works :-)

only a few seconds currently:

[main] INFO org.apache.maven.cli.event.ExecutionEventLogger - Subject Area OMAS FVT .............................. SUCCESS [ 36.095 s]

see https://dev.azure.com/ODPi/Egeria/_build/results?buildId=8410&view=logs&j=ac0a620f-bc12-5590-dc41-1227e7934d92&t=20d5b08f-cc4c-56d9-a78d-7c0974959311

planetf1 commented 4 years ago

Another observation - we can increase startup time of the egeria chassis further by ensuring we set springdoc.api-docs.enabled=false (or export SPRINGDOC_API_DOCS_ENABLED=false) Will look at adding to existing invocations on next round of changes (cc: @davidradl )

planetf1 commented 4 years ago

Next action on this - add parm above & add docs

planetf1 commented 4 years ago

this is done