-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_ej2.py
More file actions
85 lines (71 loc) · 2.04 KB
/
Copy pathtest_ej2.py
File metadata and controls
85 lines (71 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import os
import pytest
from utils import git, docker, config, scripts, line_parser
CLIENT_CONFIG_A = {
'loop_amount' : 5,
'loop_period' : '100ms',
'log_level' :'DEBUG'
}
CLIENT_CONFIG_B = {
'loop_amount' : 2,
'loop_period' : '250ms',
'log_level' :'INFO'
}
SERVER_CONFIG_A = {
'listen_backlog' : 8,
'logging_level': 'DEBUG'
}
SERVER_CONFIG_B = {
'listen_backlog' : 16,
'logging_level': 'INFO'
}
def _test_config(client_config=None, server_config=None):
config.server(**(server_config or {}))
config.client(**(client_config or {}))
scripts.generate_docker_compose(1)
docker.up()
logs = docker.logs()
for line in logs:
print(line, end='')
msg = line_parser.parse(line)
if not msg:
continue
assert(msg['result'] != line_parser.Result.FAIL)
if msg['action'] == 'config':
if msg['source'] == 'server':
if not server_config:
continue
for key, value in server_config.items():
assert (msg[key] == str(value)), f'Expected {key} to be {value}, but found {msg[key]}'
else:
if not client_config:
continue
for key, value in client_config.items():
assert (msg[key] == str(value)), f'Expected {key} to be {value}, but found {msg[key]}'
elif msg['action'] == 'exit':
assert (msg['source'] != 'server'), 'Server should keep running even if clients disconnect'
assert (msg['result'] == line_parser.Result.SUCCESS), 'Expected client to exit succesfuly'
elif msg['action'] == 'loop_finished':
break
docker.down()
@pytest.fixture(autouse=True, scope='module')
def setup():
os.chdir(os.environ['REPO_PATH'])
git.reset_branch()
git.switch_branch('ej2')
docker.stop_all()
docker.prune()
#Build images only once
docker.build()
@pytest.fixture(autouse=True)
def beforeEach():
git.reset_branch()
docker.down()
def test_client_config_A():
_test_config(client_config=CLIENT_CONFIG_A)
def test_client_config_B():
_test_config(client_config=CLIENT_CONFIG_B)
def test_server_config_A():
_test_config(server_config=SERVER_CONFIG_A)
def test_server_config_B():
_test_config(server_config=SERVER_CONFIG_B)