From 2587e35615cfa53af0212a9c2b594590cfcee051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20Krone=CC=81?= Date: Mon, 5 Feb 2024 15:31:40 +0100 Subject: [PATCH] Fix a bug in mongoreader preventing using existing collections --- locust_plugins/mongoreader.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/locust_plugins/mongoreader.py b/locust_plugins/mongoreader.py index a2242d2..c5a64d1 100644 --- a/locust_plugins/mongoreader.py +++ b/locust_plugins/mongoreader.py @@ -34,9 +34,10 @@ 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: