run-tests: explicitly close fds when spwaning watchman

Summary:
Previously, the watchman forground server could inherit other fds (ex.  the one
that waits for "watchman --version --no-spawn" output) and cause the read of
"watchman --version" to take forever. This patch closes related fds to solve
the issue.

Reviewed By: wez

Differential Revision: D8846430

fbshipit-source-id: d65f3377ac3b2277d1be7149a4ceb590f9a184a2
This commit is contained in:
Jun Wu 2018-07-13 17:16:00 -07:00 committed by Facebook Github Bot
parent 4ce060d4c7
commit a5dfe6b736

View File

@ -1004,8 +1004,10 @@ class Test(unittest.TestCase):
if os.name == "nt": if os.name == "nt":
sockfile = "\\\\.\\pipe\\watchman-test-%s" % uuid.uuid4().hex sockfile = "\\\\.\\pipe\\watchman-test-%s" % uuid.uuid4().hex
closefd = False
else: else:
sockfile = os.path.join(self._watchmandir, b"sock") sockfile = os.path.join(self._watchmandir, b"sock")
closefd = True
self._watchmansock = sockfile self._watchmansock = sockfile
@ -1037,7 +1039,7 @@ class Test(unittest.TestCase):
with open(clilogfile, "wb") as f: with open(clilogfile, "wb") as f:
self._watchmanproc = subprocess.Popen( self._watchmanproc = subprocess.Popen(
argv, env=envb, stdin=None, stdout=f, stderr=f argv, env=envb, stdin=None, stdout=f, stderr=f, close_fds=closefd
) )
# Wait for watchman socket to become available # Wait for watchman socket to become available
@ -1055,7 +1057,7 @@ class Test(unittest.TestCase):
try: try:
# The watchman CLI can wait for a short time if sockfile # The watchman CLI can wait for a short time if sockfile
# is not ready. # is not ready.
subprocess.check_output(argv, env=envb) subprocess.check_output(argv, env=envb, close_fds=closefd)
watchmanavailable = True watchmanavailable = True
except Exception: except Exception:
time.sleep(0.1) time.sleep(0.1)