Fix tests that deadlock with `--jobs=1`.

Failed in 1h 34m
:pipeline:
Print Test Summary for Shards
2/20
:mac: macOS (shard 1)curl -sS https://raw.githubusercontent.com/bazelbuild/continuous-integration/master/buildkite/bazelci.py?1718942147 -o bazelci.py && python3 bazelci.py runner --task=macos_v2 --http_config=https://raw.githubusercontent.com/fweikert/bazel/macos_v2/.bazelci/postsubmit.yml
Waited 7s
Ran in 7m 25s
3/20
:mac: macOS (shard 2)curl -sS https://raw.githubusercontent.com/bazelbuild/continuous-integration/master/buildkite/bazelci.py?1718942147 -o bazelci.py && python3 bazelci.py runner --task=macos_v2 --http_config=https://raw.githubusercontent.com/fweikert/bazel/macos_v2/.bazelci/postsubmit.yml
Waited 4s
Ran in 9m 3s
12/20
:mac: macOS (shard 11)curl -sS https://raw.githubusercontent.com/bazelbuild/continuous-integration/master/buildkite/bazelci.py?1718942147 -o bazelci.py && python3 bazelci.py runner --task=macos_v2 --http_config=https://raw.githubusercontent.com/fweikert/bazel/macos_v2/.bazelci/postsubmit.yml
Waited 11s
Ran in 5m 31s
15/20
:mac: macOS (shard 14)curl -sS https://raw.githubusercontent.com/bazelbuild/continuous-integration/master/buildkite/bazelci.py?1718942147 -o bazelci.py && python3 bazelci.py runner --task=macos_v2 --http_config=https://raw.githubusercontent.com/fweikert/bazel/macos_v2/.bazelci/postsubmit.yml
Waited 7s
Ran in 9m 23s
19/20
:mac: macOS (shard 18)curl -sS https://raw.githubusercontent.com/bazelbuild/continuous-integration/master/buildkite/bazelci.py?1718942147 -o bazelci.py && python3 bazelci.py runner --task=macos_v2 --http_config=https://raw.githubusercontent.com/fweikert/bazel/macos_v2/.bazelci/postsubmit.yml
Waited 6s
Ran in 1h 7m
20/20
:mac: macOS (shard 19)curl -sS https://raw.githubusercontent.com/bazelbuild/continuous-integration/master/buildkite/bazelci.py?1718942147 -o bazelci.py && python3 bazelci.py runner --task=macos_v2 --http_config=https://raw.githubusercontent.com/fweikert/bazel/macos_v2/.bazelci/postsubmit.yml
Waited 2s
Ran in 7m 17s
Total Job Run Time: 12h 15m