test: Add test for new pairlock deduplication

This commit is contained in:
Matthias
2026-04-06 09:58:58 +02:00
parent 9582bd3cd7
commit 6712d20578
2 changed files with 31 additions and 2 deletions
+29
View File
@@ -158,3 +158,32 @@ def test_PairLocks_reason(use_db):
PairLocks.reset_locks()
PairLocks.use_db = True
@pytest.mark.parametrize("use_db", (False, True))
@pytest.mark.usefixtures("init_persistence")
def test_PairLocks_no_duplicates(use_db, time_machine):
PairLocks.timeframe = "5m"
PairLocks.use_db = use_db
# No lock should be present
assert len(PairLocks.get_all_locks()) == 0
time_machine.move_to("2026-01-05 20:00:05 +00:00", tick=False)
assert PairLocks.use_db == use_db
PairLocks.lock_pair("XRP/USDT", dt_now() + timedelta(minutes=4), "TestLock1")
assert len(PairLocks.get_all_locks()) == 1
PairLocks.lock_pair("XRP/USDT", dt_now() + timedelta(minutes=4), "TestLock1")
assert len(PairLocks.get_all_locks()) == 1
# Different Reason - should create a new lock
PairLocks.lock_pair("XRP/USDT", dt_now() + timedelta(minutes=4), "TestLock2")
assert len(PairLocks.get_all_locks()) == 2
# Different end-time - should create a new lock
PairLocks.lock_pair("XRP/USDT", dt_now() + timedelta(minutes=5), "TestLock1")
assert len(PairLocks.get_all_locks()) == 3
# Different side - should create a new lock
PairLocks.lock_pair("XRP/USDT", dt_now() + timedelta(minutes=4), "TestLock1", side="long")
assert len(PairLocks.get_all_locks()) == 4
+2 -2
View File
@@ -1434,8 +1434,8 @@ def test_rpc_add_and_delete_lock(mocker, default_conf):
pair = "ETH/BTC"
rpc._rpc_add_lock(pair, datetime.now(UTC) + timedelta(minutes=4), "", "*")
rpc._rpc_add_lock(pair, datetime.now(UTC) + timedelta(minutes=5), "", "*")
rpc._rpc_add_lock(pair, datetime.now(UTC) + timedelta(minutes=10), "", "*")
rpc._rpc_add_lock(pair, datetime.now(UTC) + timedelta(minutes=20), "", "*")
rpc._rpc_add_lock(pair, datetime.now(UTC) + timedelta(minutes=50), "", "*")
locks = rpc._rpc_locks()
assert locks["lock_count"] == 3