Skip to content

Commit

Permalink
make use of retry lib
Browse files Browse the repository at this point in the history
Signed-off-by: tison <wander4096@gmail.com>
  • Loading branch information
tisonkun committed Jan 22, 2022
1 parent 7b573af commit 662f499
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 36 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
PyYAML==5.4
apache-skywalking==0.5.0
retry==0.9.2
52 changes: 16 additions & 36 deletions tests/e2e/run_e2e.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import os
import sys
import time
from difflib import Differ
from os.path import dirname
from retry.api import retry_call

import argparse
import yaml
import requests
import time

try:
from yaml import CSafeLoader as Loader
except ImportError:
from yaml import SafeLoader as Loader

def validate(expected_file_name):
with open(expected_file_name) as expected_data_file:
def validate(excepted_file):
with open(excepted_file) as expected_data_file:
expected_data = os.linesep.join(expected_data_file.readlines())

response = requests.post(url='http://0.0.0.0:12800/dataValidate', data=expected_data)
Expand All @@ -35,6 +33,13 @@ def validate(expected_file_name):

return response

def health_check():
requests.get('http://0.0.0.0:8081/healthCheck', timeout=5)

def call_target_path(target_path):
requests.get('http://0.0.0.0:8081{0}'.format(target_path), timeout=5)


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--expected_file', help='File name which includes expected reported value')
Expand All @@ -43,35 +48,10 @@ def validate(expected_file_name):

args = parser.parse_args()

health_check_times = 0
while True:
if health_check_times > 30:
raise RuntimeError("Producer health check times exceeded")

try:
requests.get('http://0.0.0.0:8081/healthCheck', timeout=5)
except Exception as e:
print(e)
health_check_times += 1
time.sleep(2)
continue

# health check passed
break

retry_times = 0
while True:
if retry_times > args.max_retry_times:
raise RuntimeError("Max retry times exceeded")

try:
requests.get('http://0.0.0.0:8081{0}'.format(args.target_path), timeout=5)
except Exception as e:
print(e)
retry_times += 1
time.sleep(2)
continue
import logging
logging.basicConfig()
retry_call(health_check, tries=30, delay=2)
retry_call(call_target_path, fargs=[args.target_path], tries=args.max_retry_times, delay=2)

res = validate(args.expected_file)
assert res.status_code == 200
break
res = validate(args.expected_file)
assert res.status_code == 200

0 comments on commit 662f499

Please sign in to comment.