Skip to content

Commit

Permalink
Fix a bug in mongoreader preventing using existing collections (#167)
Browse files Browse the repository at this point in the history
Fix a bug in mongoreader preventing using existing collections (it didnt like being being cast to a boolean)
  • Loading branch information
DennisKrone authored Feb 5, 2024
1 parent ea7d3ac commit 8a3e308
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions locust_plugins/mongoreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ def __init__(
"""
self.timestamp_field = timestamp_field
self.coll: Collection = (
coll or MongoClient(env["LOCUST_MONGO"])[env["LOCUST_MONGO_DATABASE"]][env["LOCUST_MONGO_COLLECTION"]]
)
if not coll:
self.coll: Collection = MongoClient(env["LOCUST_MONGO"])[env["LOCUST_MONGO_DATABASE"]][
env["LOCUST_MONGO_COLLECTION"]
]
else:
self.coll = coll
self.cursor: Cursor = self.coll.find(filter, sort=[(self.timestamp_field, 1)])
records_in_buffer = self.cursor._refresh() # trigger fetch immediately instead of waiting for the first next()
if not records_in_buffer:
Expand Down
3 changes: 2 additions & 1 deletion test/test_cloudwatch_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@

setup_logging("INFO", None)


class CloudwatchMock:
def __init__(self):
self.call_count = 0
self.metrics_dict = {}


def put_metric_data(self, Namespace, MetricData):
self.call_count += 1
self.metrics_dict[Namespace] = MetricData


cw = CloudwatchMock()


def on_locust_init(environment, **_kwargs):
CloudwatchAdapter(environment, "MyExampleService", "perf", cw)

Expand Down

0 comments on commit 8a3e308

Please sign in to comment.