Skip to content

Commit b3f4363

Browse files
committed
add container test
1 parent 223b78b commit b3f4363

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

main.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
from piper.services import TestMessageAdder, StringValue
22
from piper.envs import CurrentEnv
3+
from piper.configurations import get_configuration
34

45
import asyncio
56
from loguru import logger
6-
logger.add("file.log", level="INFO")
7+
logger.add("file.log", level="INFO", backtrace=True, diagnose=True, rotation='5 MB')
78

89
if __name__ == '__main__':
10+
cfg = get_configuration()
911
loop = asyncio.get_event_loop()
1012
with CurrentEnv() as env:
1113
x = StringValue(value="hello, world")
12-
adder = TestMessageAdder(appender="!", port=8788)
14+
adder = TestMessageAdder(appender="!", port=cfg.docker_app_port)
1315
result = loop.run_until_complete(adder(x))
1416
print(result)
1517

1618
x = StringValue(value="hello, world")
17-
adder = TestMessageAdder(appender="!", port=8788)
19+
adder = TestMessageAdder(appender="!", port=cfg.docker_app_port)
1820
result = loop.run_until_complete(adder(x))
1921
print(result)
2022
adder.rm_container()

piper/base/executors.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ async def __call__(self, *args, **kwargs):
6868
request_dict = inputs_to_dict(*args, **kwargs)
6969
print('request_dict', request_dict)
7070
async with aiohttp.ClientSession() as session:
71-
async with session.post(f'http://{self.host}:{self.port}/{function}', json=request_dict) as resp:
71+
url = f'http://{self.host}:{self.port}/{function}'
72+
logger.info(f'run function with url {url} and data {request_dict}')
73+
async with session.post(url, json=request_dict) as resp:
7274
return await resp.json()
7375

7476

piper/configurations.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
class Configuration:
22
path = "/Users/olegsokolov/PycharmProjects/piper/applications"
33
path = "/home/pavel/repo/piper_new_out/"
4+
test_path = "/home/pavel/repo/piper_test_out/"
45
piper_path = "piper"
56
default_env = "docker"
7+
docker_app_port = 8788
68
env = None
79

10+
# start time and counter
11+
wait_on_iter = 0.5
12+
n_iters = 10
13+
814

915
def get_configuration():
1016
return Configuration

tests/container_test.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1+
import docker
12
import os
23
import sys
4+
import asyncio
35
root_dir = os.path.join(os.path.realpath(os.path.pardir), 'piper')
46
sys.path.insert(1, root_dir)
57

68
from piper.utils import docker_utils as du
79
from piper.envs import CurrentEnv
10+
from piper.envs import is_docker_env
11+
from piper.configurations import get_configuration
12+
from piper.base.executors import copy_piper, copy_scripts
13+
from piper.services import TestMessageAdder, StringValue
814

915
def test_start_container():
10-
with CurrentEnv() as env:
11-
print(env)
12-
assert True == True
16+
cfg = get_configuration()
17+
loop = asyncio.get_event_loop()
18+
init_value = "TEST_container_"
19+
x = StringValue(value=init_value)
20+
need_result = f'{init_value}TEST'
21+
adder = TestMessageAdder(appender="!", port=cfg.docker_app_port)
22+
result = loop.run_until_complete(adder(x))
23+
print(result)
24+
adder.rm_container()
1325

14-
# du.get_container('asba', 'dkfja')
15-
16-
17-
import os
18-
19-
def test_dummy():
20-
print(f'file {os.path.dirname(__file__)}')
21-
print(f'name', os.path.dirname(__name__))
22-
assert True == True
26+
assert result.get('value') == need_result

0 commit comments

Comments
 (0)