Skip to content

Commit 6058cae

Browse files
committed
cleanup uses_services plugin test names/comments
1 parent 00d90ad commit 6058cae

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

pants-plugins/uses_services/mongo_rules_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def platform(
9494

9595

9696
# Warning this requires that mongo be running
97-
def test_is_running(rule_runner: RuleRunner) -> None:
97+
def test_mongo_is_running(rule_runner: RuleRunner) -> None:
9898
request = UsesMongoRequest()
9999
mock_platform = platform()
100100

@@ -157,7 +157,7 @@ def test_is_running(rule_runner: RuleRunner) -> None:
157157
),
158158
),
159159
)
160-
def test_not_running(rule_runner: RuleRunner, mock_platform: Platform) -> None:
160+
def test_mongo_not_running(rule_runner: RuleRunner, mock_platform: Platform) -> None:
161161
request = UsesMongoRequest(
162162
db_host="127.100.20.7",
163163
db_port=10, # unassigned port, unlikely to be used

pants-plugins/uses_services/scripts/is_mongo_running.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@
1717
def _is_mongo_running(
1818
db_host: str, db_port: int, db_name: str, connection_timeout_ms: int
1919
) -> bool:
20+
"""Connect to mongo with connection logic that mirrors the st2 code.
21+
22+
In particular, this is based on st2common.models.db.db_setup().
23+
This should not import the st2 code as it should be self-contained.
24+
"""
2025
# late import so that __file__ can be imported in the pants plugin without these imports
2126
import mongoengine
2227
from pymongo.errors import ConnectionFailure
2328
from pymongo.errors import ServerSelectionTimeoutError
2429

25-
# cf st2common.models.db.setup()
2630
connection = mongoengine.connection.connect(
2731
db_name,
2832
host=db_host,
@@ -31,7 +35,7 @@ def _is_mongo_running(
3135
serverSelectionTimeoutMS=connection_timeout_ms,
3236
)
3337

34-
# connection.connect() is lazy. Make a command to test connection.
38+
# connection.connect() is lazy. Make a command to test the connection.
3539
try:
3640
# The ismaster command is cheap and does not require auth
3741
connection.admin.command("ismaster")

0 commit comments

Comments
 (0)