Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry for request_response_cycle #157

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 OSError as e:
if attempt < 3:
time.sleep(1)
else:
raise e


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