1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 15:38:11 +00:00

tests/device_tests: don't wait forever for emulator to start listening

This commit is contained in:
Pavol Rusnak 2019-09-10 23:34:28 +02:00
parent 775f5b4e66
commit 9898b9f208
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -46,12 +46,18 @@ class EmulatorWrapper:
env["TREZOR_PROFILE_DIR"] = self.workdir.name env["TREZOR_PROFILE_DIR"] = self.workdir.name
# for firmware 2.1.1 and older # for firmware 2.1.1 and older
env["TREZOR_PROFILE"] = self.workdir.name env["TREZOR_PROFILE"] = self.workdir.name
self.client = None
self.process = subprocess.Popen( self.process = subprocess.Popen(
args, cwd=self.workdir.name, env=ENV, stdout=open(os.devnull, "w") args, cwd=self.workdir.name, env=ENV, stdout=open(os.devnull, "w")
) )
# wait until emulator is started # wait until emulator is listening
i = 0
while True: while True:
try: try:
i += 1
if i > 100:
self.__exit__(None, None, None)
raise RuntimeError("Can't connect to emulator")
self.transport = get_transport("udp:127.0.0.1:21324") self.transport = get_transport("udp:127.0.0.1:21324")
except TransportException: except TransportException:
time.sleep(0.1) time.sleep(0.1)
@ -73,7 +79,8 @@ class EmulatorWrapper:
return self return self
def __exit__(self, exc_type, exc_value, traceback): def __exit__(self, exc_type, exc_value, traceback):
self.client.close() if self.client:
self.client.close()
self.process.terminate() self.process.terminate()
try: try:
self.process.wait(1) self.process.wait(1)