forked from babsey/insite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
53 lines (47 loc) · 1.63 KB
/
conftest.py
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
import pytest
import subprocess
import signal
import requests
import time
import os
@pytest.fixture(scope="session")
def nest_simulation(request):
logfile = open("docker-compose.log", "w")
subprocess.run(["docker-compose", "build"], stdout=logfile, stderr=subprocess.STDOUT)
process = subprocess.Popen(["docker-compose", "up"], stdout=logfile, stderr=subprocess.STDOUT)
def finalize():
# process.send_signal(signal.SIGINT)
os.kill(process.pid, signal.SIGINT)
try:
process.wait(10)
except subprocess.TimeoutExpired:
print("Sending SIGKILL to docker-compose")
os.kill(process.pid, signal.SIGKILL)
process.wait()
subprocess.run(["docker-compose", "down"], stdout=logfile, stderr=subprocess.STDOUT)
logfile.close()
request.addfinalizer(finalize)
begin_time = time.time()
while True:
time.sleep(1.0)
try:
r = requests.get("http://localhost:9000/version")
if r.status_code == 200:
break
except requests.exceptions.ConnectionError:
pass
current_time = time.time()
if current_time - begin_time > 60:
pytest.fail('Timeout during container start')
while True:
time.sleep(1.0)
try:
r = requests.get("http://localhost:8080/version")
if r.status_code == 200:
break
except requests.exceptions.ConnectionError:
pass
current_time = time.time()
if current_time - begin_time > 60:
pytest.fail('Timeout during container start')
return process