Skip to content

Commit

Permalink
Merge branch 'master' into achiurizo/sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
achiurizo committed Jun 12, 2019
2 parents 91197bc + c19588d commit c58da0a
Show file tree
Hide file tree
Showing 18 changed files with 450 additions and 243 deletions.
6 changes: 6 additions & 0 deletions .circleci/config.yml
Expand Up @@ -318,6 +318,12 @@ jobs:
kubectl set image statefulset childchain-samrong childchain=$DOCKER_IMAGE
while true; do if [ "$(kubectl get pods childchain-samrong-0 -o jsonpath=\"{.status.phase}\" | grep Running)" ]; then break; fi; done
kubectl set image statefulset watcher-samrong watcher=$DOCKER_IMAGE
while true; do if [ "$(kubectl get pods watcher-samrong-0 | grep 1/1)" ]; then break; fi; done
- run:
name: Functional Tests
command: |
apt-get update && apt-get install python3-requests -y
python3 .circleci/test_runner.py
build_and_deploy_staging:
docker:
Expand Down
104 changes: 104 additions & 0 deletions .circleci/test_runner.py
@@ -0,0 +1,104 @@
#!/usr/bin/python3
import logging
import os
import sys
import time

import requests


def create_job(test_runner: str) -> str:
''' Create a job in the test runner. Returns the job ID
'''
payload = {
"job": {
"command": "npm",
"args": ["run", "ci-test-fast"],
"cwd": "/home/omg/omg-js"
}
}
try:
request = requests.post(test_runner + '/job', json=payload)
except ConnectionError:
logging.critical('Could not connect to the test runner')
sys.exit(1) # Return a non-zero exit code so CircleCI fails

logging.info('Job created: {}'.format(
request.content.decode('utf-8'))
)
return request.content.decode('utf-8')


def check_job_completed(test_runner: str, job_id: str):
''' Get the status of the job from the test runner
'''
start_time = int(time.time())
while True:
if start_time >= (start_time + 360):
logging.critical('Test runner did not complete within six minutes')
sys.exit(1) # Return a non-zero exit code so CircleCI fails
try:
request = requests.get(
'{}/job/{}/status'.format(test_runner, job_id),
headers={'Cache-Control': 'no-cache'}
)
except ConnectionError:
logging.critical('Could not connect to the test runner')
sys.exit(1) # Return a non-zero exit code so CircleCI fails
if 'Exited' in request.content.decode('utf-8'):
logging.info('Job completed successfully')
break


def check_job_result(test_runner: str, job_id: str):
''' Check the result of the job. This is the result of the tests that are
executed against the push. If they all pass 'true' is returned.
'''
try:
request = requests.get(
test_runner + '/job/{}/success'.format(job_id),
headers={'Cache-Control': 'no-cache'}
)
except ConnectionError:
logging.critical('Could not connect to the test runner')
sys.exit(1)
if 'true' in request.content.decode('utf-8'):
logging.info('Tests completed successfully')


def get_envs() -> dict:
''' Get the environment variables for the workflow
'''
envs = {}
test_runner = os.getenv('TEST_RUNNER_SERVICE')
if test_runner is None:
logging.critical('Test runner service ENV missing')
sys.exit(1) # Return a non-zero exit code so CircleCI fails

envs['TEST_RUNNER_SERVICE'] = test_runner
return envs


def start_workflow():
''' Get the party started
'''
logging.info('Workflow started')
envs = get_envs()
job_id = str(create_job(envs['TEST_RUNNER_SERVICE']))
check_job_completed(envs['TEST_RUNNER_SERVICE'], job_id)
check_job_result(envs['TEST_RUNNER_SERVICE'], job_id)


def set_logger():
''' Sets the logging module parameters
'''
root = logging.getLogger('')
for handler in root.handlers:
root.removeHandler(handler)
format = '%(asctime)s %(levelname)-8s:%(message)s'
logging.basicConfig(format=format, level='INFO')


if __name__ == '__main__':
set_logger()
start_workflow()
3 changes: 2 additions & 1 deletion apps/omg/lib/omg/state.ex
Expand Up @@ -24,13 +24,14 @@ defmodule OMG.State do
alias OMG.Recorder
alias OMG.State.Core
alias OMG.State.Transaction
alias OMG.State.Transaction.Validator
alias OMG.Utxo

use GenServer
use OMG.Utils.Metrics
use OMG.Utils.LoggerExt

@type exec_error :: Core.exec_error()
@type exec_error :: Validator.exec_error()

### Client

Expand Down

0 comments on commit c58da0a

Please sign in to comment.