Commit bdf77571 authored by zhifan huang's avatar zhifan huang

fix add server start test

parent 042ec0b1
......@@ -9,6 +9,7 @@ import time
import re
from subprocess import PIPE, call
from pathlib2 import Path
import logging
import re6st.tests.tools as tools
......@@ -34,6 +35,15 @@ def ip_to_serial(ip6):
return int(ip6, 16)
def wait_ps(p, timeout=1, sec=0.1):
"""implement timeout of wait"""
now = time.time()
while time.time() -timeout < now:
if p.poll() is not None:
return
time.sleep(sec)
raise Exception("{}, not terminate".format(p.pid))
class Re6stRegistry(object):
"""class run a re6st-registry service on a namespace"""
registry_seq = -1
......@@ -67,6 +77,25 @@ class Re6stRegistry(object):
self.run()
# wait the servcice started
p = self.node.Popen(['python', '-c', """if 1:
import socket, time
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
while True:
try:
s.connect(('localhost', 80))
break
except socket.error:
time.sleep(.1)
"""])
try:
wait_ps(p, 5)
except Exception as e:
logging.error("{}: {}", self.name, e)
raise e
logging.info("re6st service started")
@classmethod
def generate_name(cls):
cls.registry_seq += 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment