Skip to content

Commit

Permalink
pytest-listener: Fix flakiness on windows-py39+ due to receive() happ…
Browse files Browse the repository at this point in the history
…ening on the same timestamp as a CLEAR is received.
  • Loading branch information
jonbannister committed Nov 29, 2024
1 parent 5480ab9 commit 879f929
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pytest-listener/pytest_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@
TIMEOUT_DEFAULT = 10
DEBUG = False
logger = logging.getLogger('pytest-listener')
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s | %(levelname)-8s | %(name)s | %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
)


@pytest.yield_fixture(scope='module')
def listener(request):
""" Simple module-scoped network listener.
""" Simple module-scoped network listener.
Methods
-------
send(data, timeout): Send data to the listener
Expand Down Expand Up @@ -142,7 +147,7 @@ def _process_chunk(self, d, t):
if t is not None:
if DEBUG:
logger.info('diff %s' % (t - self.clear_time))
if t < self.clear_time:
if t <= self.clear_time:
if DEBUG:
logger.info('%s < %s' % (t, self.clear_time))
logger.info('discarding cleared %s' % d)
Expand All @@ -159,11 +164,12 @@ def _process_chunk(self, d, t):
return False

def receive(self, timeout=TIMEOUT_DEFAULT):
if timeout is not None:
MAX_COUNT = int(timeout) * 10
if timeout is None:
raise ValueError("timeout cannot be None")
max_count = int(timeout) * 10
d = None
count = 0
while d is None and count < MAX_COUNT:
while d is None and count < max_count:

d, t = self.get_data()
if d is None:
Expand Down

0 comments on commit 879f929

Please sign in to comment.