Skip to content

Commit

Permalink
Work around bug in Buck2 which causes test runner to always report en…
Browse files Browse the repository at this point in the history
…vironment changed

Reviewed By: alexmalyshev

Differential Revision: D56652977

fbshipit-source-id: 846261b2cbc4b9bed4eb8084972319199f5211f0
  • Loading branch information
jbower-fb authored and facebook-github-bot committed Apr 30, 2024
1 parent 32c9c6c commit 1ccd8ba
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions cinderx/TestScripts/cinder_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,55 @@ def worker_main(args):
WorkReceiver(pipe).run(ns)


# TODO(T184566736) Remove this work around for a bug in Buck2 which causes
# us to be the parent of fire-and-forget logging processes.
def fix_env_always_changed_issue():
# Build a list of our already existing child-processes.
current_pid = os.getpid()
result = subprocess.run(
["pgrep", "-P", str(current_pid)], capture_output=True, text=True)
pids = result.stdout.strip().split("\n")
child_pids_ignore = {int(pid) for pid in pids if pid}


# This is a copy of test.support.reap_children() altered to ignore our
# initial children. We monkey-patch this version in below.
def reap_children():
"""Use this function at the end of test_main() whenever sub-processes
are started. This will help ensure that no extra children (zombies)
stick around to hog resources and create problems when looking
for refleaks.
"""

# Need os.waitpid(-1, os.WNOHANG): Windows is not supported
if not (hasattr(os, 'waitpid') and hasattr(os, 'WNOHANG')):
return

# Reap all our dead child processes so we don't leave zombies around.
# These hog resources and might be causing some of the buildbots to die.
while True:
try:
# Read the exit status of any child process which already completed
pid, status = os.waitpid(-1, os.WNOHANG)
except OSError:
break

# *CINDER CHANGE HERE*
if pid in child_pids_ignore:
continue

if pid == 0:
break

support.print_warning(f"reap_children() reaped child process {pid}")
support.environment_altered = True


support.reap_children = reap_children


def user_selected_main(args):
fix_env_always_changed_issue()
test_runner = UserSelectedCinderRegrtest()
sys.argv[1:] = args.rest[1:]
test_runner.main(args.test)
Expand Down

0 comments on commit 1ccd8ba

Please sign in to comment.