Skip to content

Commit

Permalink
Add retry for request_response_cycle (pytest-dev#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
U2FsdGVkX1 committed Nov 22, 2024
1 parent 1c89f84 commit 75d92c8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
1.0.2 (2024-11-22)
------------------

- Add retry for request_response_cycle. Fixed
https://github.com/pytest-dev/pytest-xprocess/issues/154


1.0.1 (2024-04-31)
------------------

Expand Down
18 changes: 13 additions & 5 deletions tests/test_process_initialization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import socket
import sys
import time
from pathlib import Path

import pytest
Expand All @@ -12,11 +13,18 @@
def request_response_cycle(tcp_port, data):
"""test started server instance by sending
request and checking response"""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.connect(("localhost", tcp_port))
sock.sendall(bytes(data, "utf-8"))
received = str(sock.recv(1024), "utf-8")
return received == data.upper()
for attempt in range(4):
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.connect(("localhost", tcp_port))
sock.sendall(bytes(data, "utf-8"))
received = str(sock.recv(1024), "utf-8")
return received == data.upper()
except socket.error as e:
if attempt < 3:
time.sleep(1)
else:
raise e


@pytest.mark.parametrize("proc_name", ["s1", "s2", "s3"])
Expand Down

0 comments on commit 75d92c8

Please sign in to comment.