From a21e534a676f78949bf323ce7b4541b22a444209 Mon Sep 17 00:00:00 2001 From: Atsushi Neki Date: Thu, 23 May 2019 05:13:11 +0000 Subject: [PATCH] BE-648 Add e2e sanity check to the verification Change-Id: I7f9d4aebb648cce6ad94065defe778244e99dce5 Signed-off-by: Atsushi Neki --- Jenkinsfile | 19 +++++++++++++++++++ app/platform/fabric/e2e-test/environment.py | 7 +++++++ app/platform/fabric/e2e-test/explorer.feature | 1 + .../fabric/e2e-test/steps/explorer_impl.py | 10 ++++++++-- package.json | 6 +++++- 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b78783b48..46d7e42e0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -86,6 +86,25 @@ node ('hyp-x') { // trigger build on x86_64 node } } + // Run npm tests + stage("E2E Tests for Sanity-check") { + wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) { + try { + dir("${ROOTDIR}") { + sh ''' + npm install + npm run e2e-test-sanitycheck:ci + ''' + } + } + catch (err) { + failure_stage = "e2e tests" + currentBuild.result = 'FAILURE' + throw err + } + } + } + // Docs HTML Report stage("Doc Output") { wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) { diff --git a/app/platform/fabric/e2e-test/environment.py b/app/platform/fabric/e2e-test/environment.py index 32006efd4..f1be91ddc 100644 --- a/app/platform/fabric/e2e-test/environment.py +++ b/app/platform/fabric/e2e-test/environment.py @@ -51,6 +51,13 @@ def before_scenario(context, scenario): def after_scenario(context, scenario): + + if scenario.status == "failed": + print("Explorer container log:") + subprocess.call("docker logs explorer.mynetwork.com 2>&1", shell=True) + print("Explorer-DB container log:") + subprocess.call("docker logs explorerdb.mynetwork.com 2>&1", shell=True) + # Display memory usage before tearing down the network mem = psutil.virtual_memory() print("Memory Info Before Network Teardown:\n\tFree: {}\n\tUsed: {}\n\tPercentage: {}\n".format(mem.free, mem.used, mem.percent)) diff --git a/app/platform/fabric/e2e-test/explorer.feature b/app/platform/fabric/e2e-test/explorer.feature index 470f7e756..a78df247e 100644 --- a/app/platform/fabric/e2e-test/explorer.feature +++ b/app/platform/fabric/e2e-test/explorer.feature @@ -32,6 +32,7 @@ Feature: Bootstrapping Hyperledger Explorer # Then JSON at path ".channels" should equal ["mychannel"] @basic +@sanitycheck # @doNotDecompose Scenario Outline: [] Bring up explorer with fabric-samples/ and send requests to the basic REST API functions successfully # Start a fabric network by using fabric-samples/ diff --git a/app/platform/fabric/e2e-test/steps/explorer_impl.py b/app/platform/fabric/e2e-test/steps/explorer_impl.py index 692d17625..3b69ac623 100644 --- a/app/platform/fabric/e2e-test/steps/explorer_impl.py +++ b/app/platform/fabric/e2e-test/steps/explorer_impl.py @@ -103,11 +103,17 @@ def start_balancetransfer_impl(context): try: command = ["./runApp.sh"] - subprocess.Popen(command, shell=True, env=updated_env, stdout=FNULL) + p = subprocess.Popen(command, shell=True, env=updated_env, stdout=subprocess.PIPE) except: print("Failed to start application: {0}".format(sys.exc_info()[1])) - time.sleep(10) + while True: + line = p.stdout.readline() + if "SERVER STARTED" in line: + print(line) + break + else: + time.sleep(1) try: command = ["./testAPIs.sh"] diff --git a/package.json b/package.json index 5970264c8..047744f02 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "license": "Apache-2.0", "devDependencies": { "babel-eslint": "10.0.1", + "cross-env": "^5.2.0", "eslint": "^5.16.0", "eslint-config-airbnb": "^17.0.0", "eslint-plugin-import": "^2.13.0", @@ -84,9 +85,12 @@ "precommit": "lint-staged && ./verify-license.sh", "e2e-test-check-tool": "/bin/bash -c 'if [[ -z $(which configtxgen) ]]; then echo \"### Need to install tools ###\n\"; exit -1; fi'", "e2e-test-check-img": "/bin/bash -c 'if [[ -z $(docker images -q hyperledger/fabric-peer:latest) ]]; then echo \"### Need to pull fabric images ###\n\"; exit -1; fi'", + "e2e-test-setup-tool:ci": "/bin/bash -c 'mkdir fabric-samples; pushd fabric-samples; curl -sSL https://raw.githubusercontent.com/hyperledger/fabric-samples/release-1.4/scripts/bootstrap.sh | bash -s; popd'", "e2e-test-setup-env": "cd app/platform/fabric/e2e-test; if [ ! -e e2e-test ]; then virtualenv e2e-test; fi && . ./e2e-test/bin/activate && pip install -r requirement.txt", "e2e-test-setup-img": "./build_docker_image.sh", "e2e-test-run": "cd app/platform/fabric/e2e-test; . ./e2e-test/bin/activate && behave explorer.feature", - "e2e-test": "run-s e2e-test-check-tool e2e-test-check-img e2e-test-setup-env e2e-test-setup-img e2e-test-run" + "e2e-test-run-sanitycheck": "cd app/platform/fabric/e2e-test; . ./e2e-test/bin/activate && behave --tags=@sanitycheck --stop --no-skipped explorer.feature", + "e2e-test": "run-s e2e-test-check-tool e2e-test-check-img e2e-test-setup-env e2e-test-setup-img e2e-test-run", + "e2e-test-sanitycheck:ci": "cross-env PATH=$PATH:$PWD/fabric-samples/bin run-s e2e-test-setup-tool:ci e2e-test-check-tool e2e-test-check-img e2e-test-setup-env e2e-test-setup-img e2e-test-run-sanitycheck" } }