diff --git a/src/main/java/org/jahia/modules/sam/healthcheck/probes/SupportedStackJSModulesProbe.java b/src/main/java/org/jahia/modules/sam/healthcheck/probes/SupportedStackJSModulesProbe.java index 83380da..28b67e9 100644 --- a/src/main/java/org/jahia/modules/sam/healthcheck/probes/SupportedStackJSModulesProbe.java +++ b/src/main/java/org/jahia/modules/sam/healthcheck/probes/SupportedStackJSModulesProbe.java @@ -25,20 +25,23 @@ public ProbeStatus getStatus() { String vmVendor = System.getProperty("java.vm.vendor", "Unknown"); Version jvmVersion = new Version(System.getProperty("java.version", "Unknown")); + Version graalVMVersion = new Version(System.getProperty("org.graalvm.version", "Unknown")); // This probe is only relevant for Jahia 8.2.0.0+ in which npm-modules-engine is available. // Not testing Jahia version since it is not to be backported to older versions of SAM. ProbeStatus status = new ProbeStatus("No issues to report", ProbeStatus.Health.GREEN); if (!isNpmModulesEngineStarted) { status = ProbeStatusUtils.aggregateStatus(status, "The environment is not running JS modules (npm-modules-engine stopped or not present)", ProbeStatus.Health.GREEN); - } else { - if (!vmVendor.contains("GraalVM")) { - status = ProbeStatusUtils.aggregateStatus(status, String.format("GraalVM not detected on the environment (detected vendor: %s), after switching to GraalVM make sure to enable the Javascript extension", vmVendor), ProbeStatus.Health.RED); + } else if (System.getProperty("org.graalvm.version") == null) { + status = ProbeStatusUtils.aggregateStatus(status, String.format("GraalVM not detected on the environment (detected vendor: %s with JVM version: %s), after switching to GraalVM 22.3.3+ with JVM version 17+, make sure to enable the Javascript extension", vmVendor, jvmVersion), ProbeStatus.Health.RED); + } else { + if (graalVMVersion.compareTo(new Version("22.3")) <= 0) { + status = ProbeStatusUtils.aggregateStatus(status, String.format("GraalVM version 22.3.3 or newer required (detected GraalVM version: %s)", graalVMVersion), ProbeStatus.Health.RED); } if (jvmVersion.compareTo(new Version("17")) <= 0) { - status = ProbeStatusUtils.aggregateStatus(status, String.format("GraalVM with JVM version 17 or newer required (detected: %s)", jvmVersion), ProbeStatus.Health.RED); + status = ProbeStatusUtils.aggregateStatus(status, String.format("GraalVM with JVM version 17 or newer required (detected JVM version: %s)", jvmVersion), ProbeStatus.Health.RED); } - if (vmVendor.contains("GraalVM") && !isJavaScriptModuleInstalled()) { + if (!isJavaScriptModuleInstalled()) { status = ProbeStatusUtils.aggregateStatus(status, "GraalVM is detected but the JavaScript extension is not installed", ProbeStatus.Health.RED); } } diff --git a/tests/cypress.config.ts b/tests/cypress.config.ts index ac6b0e8..6761585 100644 --- a/tests/cypress.config.ts +++ b/tests/cypress.config.ts @@ -23,6 +23,7 @@ export default defineConfig({ }, excludeSpecPattern: '*.ignore.ts', specPattern: [ + 'cypress/e2e/api/testStart.spec.begin.ts', 'cypress/e2e/api/*.spec.begin.ts', 'cypress/e2e/api/*.spec.ts', 'cypress/e2e/api/shutdown.spec.final.ts' diff --git a/tests/cypress/e2e/api/firstCheck.spec.begin.ts b/tests/cypress/e2e/api/firstCheck.spec.begin.ts new file mode 100644 index 0000000..d328b00 --- /dev/null +++ b/tests/cypress/e2e/api/firstCheck.spec.begin.ts @@ -0,0 +1,26 @@ +import {waitUntilSAMStatusGreen} from '@jahia/cypress'; +import {healthCheck} from '../../support/gql'; + +// This suite is there to ensure we get wait for SAM to return GREEN before starting the tests +// The goal is to wait for any provisioning activities that might be happening, in particular in cluster +// Failure of this suite highlights a potential issue with Jahia itself + +describe('Absence of errors in SAM at startup', () => { + it('Wait until SAM returns GREEN for medium severity', () => { + // The timeout of 3mn (180) is there to allow for the cluster (if present) to finish its synchronization + waitUntilSAMStatusGreen('MEDIUM', 180000); + cy.executeGroovy('groovy/logProvisioningDone.groovy'); + }); + + it('Check that SAM overall status is green for MEDIUM severity', () => { + healthCheck({severity: 'DEBUG'}).then(r => { + cy.log('Probes not GREEN with severity DEBUG: ' + JSON.stringify(r.probes.filter(probe => probe.status.health !== 'GREEN'))); + }); + + healthCheck({severity: 'MEDIUM'}).then(r => { + cy.then(() => { + expect(r.status.health).to.eq('GREEN'); + }); + }); + }); +}); diff --git a/tests/cypress/e2e/api/jahiaErrors.spec.begin.ts b/tests/cypress/e2e/api/jahiaErrors.spec.begin.ts index 22e96b8..e3924f0 100644 --- a/tests/cypress/e2e/api/jahiaErrors.spec.begin.ts +++ b/tests/cypress/e2e/api/jahiaErrors.spec.begin.ts @@ -3,40 +3,45 @@ import {healthCheck} from '../../support/gql'; describe('Jahia errors probe test', () => { it('Checks that JahiaErrors probe is functional', () => { healthCheck({severity: 'DEBUG'}).then(r => { - cy.log(JSON.stringify(r)); - const jahiaErrorsProbe = r.probes.find(probe => probe.name === 'JahiaErrors'); - expect(jahiaErrorsProbe.description).to.contain('Count the number of errors faced by Jahia'); - expect(jahiaErrorsProbe.severity).to.eq('DEBUG'); + cy.then(() => { + const jahiaErrorsProbe = r.probes.find(probe => probe.name === 'JahiaErrors'); + expect(jahiaErrorsProbe.description).to.contain('Count the number of errors faced by Jahia'); + expect(jahiaErrorsProbe.severity).to.eq('DEBUG'); - if (jahiaErrorsProbe.status.health === 'YELLOW') { - expect(jahiaErrorsProbe.status.message).to.contain('errors are present on the platform, errors are not expected in a production environment and we recommend reviewing these.'); - } else { - expect(jahiaErrorsProbe.status.message).to.contain('No errors are present on the platform'); - } + if (jahiaErrorsProbe.status.health === 'YELLOW') { + expect(jahiaErrorsProbe.status.message).to.contain('errors are present on the platform, errors are not expected in a production environment and we recommend reviewing these.'); + } else { + expect(jahiaErrorsProbe.status.message).to.contain('No errors are present on the platform'); + } + }); }); }); it('Check that Jahia errors probe is YELLOW when there is an error log', () => { cy.executeGroovy('groovy/simpleErrorLog.groovy'); healthCheck({severity: 'DEBUG'}).then(r => { - expect(r.status.health).to.eq('YELLOW'); - const jahiaErrorsProbe = r.probes.find(probe => probe.name === 'JahiaErrors'); - expect(jahiaErrorsProbe.status.health).to.eq('YELLOW'); - expect(jahiaErrorsProbe.severity).to.eq('DEBUG'); - // Hard to predict exact number of errors - expect(jahiaErrorsProbe.status.message).to.contain('errors are present on the platform, errors are not expected in a production environment and we recommend reviewing these.'); + cy.then(() => { + expect(r.status.health).to.eq('YELLOW'); + const jahiaErrorsProbe = r.probes.find(probe => probe.name === 'JahiaErrors'); + expect(jahiaErrorsProbe.status.health).to.eq('YELLOW'); + expect(jahiaErrorsProbe.severity).to.eq('DEBUG'); + // Hard to predict exact number of errors + expect(jahiaErrorsProbe.status.message).to.contain('errors are present on the platform, errors are not expected in a production environment and we recommend reviewing these.'); + }); }); }); it('Check that Jahia errors probe is YELLOW when there is a fatal log', () => { cy.executeGroovy('groovy/simpleFatalLog.groovy'); healthCheck({severity: 'DEBUG'}).then(r => { - expect(r.status.health).to.eq('YELLOW'); - const jahiaErrorsProbe = r.probes.find(probe => probe.name === 'JahiaErrors'); - expect(jahiaErrorsProbe.status.health).to.eq('YELLOW'); - expect(jahiaErrorsProbe.severity).to.eq('DEBUG'); - // Hard to predict exact number of errors - expect(jahiaErrorsProbe.status.message).to.contains('errors are present on the platform, errors are not expected in a production environment and we recommend reviewing these.'); + cy.then(() => { + expect(r.status.health).to.eq('YELLOW'); + const jahiaErrorsProbe = r.probes.find(probe => probe.name === 'JahiaErrors'); + expect(jahiaErrorsProbe.status.health).to.eq('YELLOW'); + expect(jahiaErrorsProbe.severity).to.eq('DEBUG'); + // Hard to predict exact number of errors + expect(jahiaErrorsProbe.status.message).to.contains('errors are present on the platform, errors are not expected in a production environment and we recommend reviewing these.'); + }); }); }); diff --git a/tests/cypress/fixtures/groovy/logProvisioningDone.groovy b/tests/cypress/fixtures/groovy/logProvisioningDone.groovy new file mode 100644 index 0000000..9e0cd54 --- /dev/null +++ b/tests/cypress/fixtures/groovy/logProvisioningDone.groovy @@ -0,0 +1 @@ +log.info("Jahia startup and provisioning is now complete, starting the Cypress tests") \ No newline at end of file diff --git a/tests/package.json b/tests/package.json index 3d6fa20..7a6091f 100644 --- a/tests/package.json +++ b/tests/package.json @@ -12,7 +12,7 @@ "main": "index.js", "license": "MIT", "devDependencies": { - "@jahia/cypress": "^3.18.1", + "@jahia/cypress": "3.20.1", "@jahia/eslint-config": "^1.1.0", "@jahia/jahia-reporter": "^1.1.16", "@typescript-eslint/eslint-plugin": "^5.48.1", diff --git a/tests/yarn.lock b/tests/yarn.lock index ed84e24..955f843 100644 --- a/tests/yarn.lock +++ b/tests/yarn.lock @@ -197,10 +197,10 @@ resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45" integrity sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA== -"@jahia/cypress@^3.18.1": - version "3.18.1" - resolved "https://registry.yarnpkg.com/@jahia/cypress/-/cypress-3.18.1.tgz#b7445bce781b1c4603ecdcb8b6c33795933d6796" - integrity sha512-QnPAONPHiVzk9RknjFAdBDNUuQtqln0dceNogXJ/rLdXYNlul4/wQiVsOYN+PueZ7+dVM8hKd1mTF3zt1Sxr1Q== +"@jahia/cypress@3.20.1": + version "3.20.1" + resolved "https://registry.yarnpkg.com/@jahia/cypress/-/cypress-3.20.1.tgz#1897d752bc7beae3362e1d85d0f1b69cac5f5e41" + integrity sha512-f3hvwXSzSPCU42z34sJ+BjZFXvmkqRq7k3cJfac/HNLrM33y7oWYpp2Nvape1W111y9WFREWLMN8iRZB+y7l0Q== dependencies: "@apollo/client" "^3.4.9" cypress-real-events "^1.11.0"