1
0
Fork 0
mirror of https://github.com/dragonflydb/dragonfly.git synced 2024-12-14 11:58:02 +00:00
dragonflydb-dragonfly/tests/dragonfly/__init__.py
Roy Jacobson 5c9c9255d2
chore: Small refactor of DflyInstance (#1951)
* Move to its own file
* Unify self.args and self.params.args earlier so it can be inspected.
2023-09-28 10:11:11 +03:00

30 lines
901 B
Python

import pytest
def dfly_args(*args):
"""Used to define a singular set of arguments for dragonfly test"""
return pytest.mark.parametrize("df_factory", args, indirect=True)
def dfly_multi_test_args(*args):
"""Used to define multiple sets of arguments to test multiple dragonfly configurations"""
return pytest.mark.parametrize("df_factory", args, indirect=True)
class PortPicker:
"""A simple port manager to allocate available ports for tests"""
def __init__(self):
self.next_port = 5555
def get_available_port(self):
while not self.is_port_available(self.next_port):
self.next_port += 1
self.next_port += 1
return self.next_port - 1
def is_port_available(self, port):
import socket
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
return s.connect_ex(("localhost", port)) != 0