-
-
Notifications
You must be signed in to change notification settings - Fork 649
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Choose distinct debug adapter ports in different tests. (#17837)
Prevents a port collision error if the two test files happen to run concurrently.
- Loading branch information
Showing
4 changed files
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
import os | ||
|
||
|
||
def debugadapter_port_for_testing() -> int: | ||
"""Return a unique-per-concurrent-process debug adapter port. | ||
Use this in Pants's (and plugins') own tests to avoid collisions. | ||
Assumes that the env var TEST_EXECUTION_SLOT has been set. If not, all tests | ||
will use the same port, and collisions may occur. | ||
""" | ||
execution_slot = os.environ.get("TEST_EXECUTION_SLOT", "0") | ||
return 22000 + int(execution_slot) |