UploadSymbolsServerTest: fix test flaking due to busy port
It is possible for these unittests to hit a race where they find an unused
port, then try to bind it, but another process has already bound to it.
Put the binding logic into a loop where we retry whenever this happens.
BUG=chromium:413014
TEST=`./cbuildbot/run_tests` passes
Change-Id: I6b3f0596f86aa08e9427e9c701d40de5a25bc0a6
Reviewed-on: https://chromium-review.googlesource.com/220193
Reviewed-by: Yu-Ju Hong <yjhong@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/scripts/upload_symbols_unittest.py b/scripts/upload_symbols_unittest.py
index d8c4d6c..7f28926 100755
--- a/scripts/upload_symbols_unittest.py
+++ b/scripts/upload_symbols_unittest.py
@@ -9,10 +9,12 @@
import BaseHTTPServer
import ctypes
+import errno
import logging
import multiprocessing
import os
import signal
+import socket
import SocketServer
import sys
import time
@@ -68,10 +70,17 @@
def SpawnServer(self, RequestHandler):
"""Spawn a new http server"""
- port = remote_access.GetUnusedPort()
- address = ('', port)
+ while True:
+ try:
+ port = remote_access.GetUnusedPort()
+ address = ('', port)
+ self.httpd = SymbolServer(address, RequestHandler)
+ break
+ except socket.error as e:
+ if e.errno == errno.EADDRINUSE:
+ continue
+ raise
self.server = 'http://localhost:%i' % port
- self.httpd = SymbolServer(address, RequestHandler)
self.httpd_pid = os.fork()
if self.httpd_pid == 0:
self.httpd.serve_forever(poll_interval=0.1)