[FIX] tests: fix race condition when spawning chrome

When Chrome is spawned, the `DevToolsActivePort`file is awaited to read
the port. Sometimes the file is read but is still empty, resulting in a
ValueError when trying to cast into integer. This happens when Chrome
did not have time yet to write into file.

With this commit, we expect the file to contain at least 5 bytes which
is enough to contain the max port number.

closes odoo/odoo#80791

X-original-commit: aab53fbb4e02461e0f23cf202d393e30a73fbc92
Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
This commit is contained in:
Christophe Monniez
2021-12-03 08:55:46 +00:00
parent 3018a91eaa
commit 9e41603743
+1 -1
View File
@@ -913,7 +913,7 @@ class ChromeBrowser:
port_file = pathlib.Path(self.user_data_dir, 'DevToolsActivePort')
for _ in range(100):
time.sleep(0.1)
if port_file.is_file():
if port_file.is_file() and port_file.stat().st_size > 5:
with port_file.open('r', encoding='utf-8') as f:
self.devtools_port = int(f.readline())
break