Skip to content

Commit 4ecf945

Browse files
authored
Fix intermittent send-to integration failures (#254)
* move DataServers into session-scoped fixtures with different ports to prevent intermittent connection problems * style
1 parent db7e49e commit 4ecf945

File tree

5 files changed

+64
-31
lines changed

5 files changed

+64
-31
lines changed

tests/integration/conftest.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from shlex import split as split_command
33

44
import pytest
5+
from tests.integration.util import DataServer
56

67
from code42cli.errors import Code42CLIError
78
from code42cli.main import cli
@@ -46,3 +47,15 @@ def _encode_response(line, encoding_type=_ENCODING_TYPE):
4647

4748
def append_profile(command):
4849
return "{} --profile {}".format(command, TEST_PROFILE_NAME)
50+
51+
52+
@pytest.yield_fixture(scope="session")
53+
def udp_dataserver():
54+
with DataServer(protocol="UDP"):
55+
yield
56+
57+
58+
@pytest.yield_fixture(scope="session")
59+
def tcp_dataserver():
60+
with DataServer(protocol="TCP"):
61+
yield

tests/integration/test_alerts.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import pytest
66
from tests.integration.conftest import append_profile
77
from tests.integration.util import assert_test_is_successful
8-
from tests.integration.util import DataServer
98

109
from code42cli.main import cli
1110

@@ -24,17 +23,24 @@ def test_alerts_search_command_returns_success_return_code(
2423

2524

2625
@pytest.mark.integration
27-
@pytest.mark.parametrize(
28-
"protocol", ["TCP", "UDP"],
29-
)
30-
def test_alerts_send_to_returns_success_return_code(
31-
runner, integration_test_profile, protocol
26+
def test_alerts_send_to_tcp_returns_success_return_code(
27+
runner, integration_test_profile, tcp_dataserver
3228
):
33-
command = "alerts send-to localhost:5140 -p {} -b {}".format(
34-
protocol, begin_date_str
29+
command = append_profile(
30+
f"alerts send-to localhost:5140 -p TCP -b '{begin_date_str}'"
3531
)
36-
with DataServer(protocol=protocol):
37-
result = runner.invoke(cli, split_command(append_profile(command)))
32+
result = runner.invoke(cli, split_command(command))
33+
assert result.exit_code == 0
34+
35+
36+
@pytest.mark.integration
37+
def test_alerts_send_to_udp_returns_success_return_code(
38+
runner, integration_test_profile, udp_dataserver
39+
):
40+
command = append_profile(
41+
f"alerts send-to localhost:5141 -p UDP -b '{begin_date_str}'"
42+
)
43+
result = runner.invoke(cli, split_command(command))
3844
assert result.exit_code == 0
3945

4046

tests/integration/test_auditlogs.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import pytest
66
from tests.integration.conftest import append_profile
77
from tests.integration.util import assert_test_is_successful
8-
from tests.integration.util import DataServer
98

109
from code42cli.main import cli
1110

@@ -17,17 +16,24 @@
1716

1817

1918
@pytest.mark.integration
20-
@pytest.mark.parametrize(
21-
"protocol", ["TCP", "UDP"],
22-
)
23-
def test_auditlogs_send_to_command_returns_success_return_code(
24-
runner, integration_test_profile, protocol
19+
def test_auditlogs_send_to_tcp_command_returns_success_return_code(
20+
runner, integration_test_profile, tcp_dataserver
2521
):
26-
command = "audit-logs send-to localhost:5140 -p {} -b '{}'".format(
27-
protocol, begin_date_str
22+
command = append_profile(
23+
f"audit-logs send-to localhost:5140 -p TCP -b '{begin_date_str}'"
2824
)
29-
with DataServer(protocol=protocol):
30-
result = runner.invoke(cli, split_command(append_profile(command)))
25+
result = runner.invoke(cli, split_command(command))
26+
assert result.exit_code == 0
27+
28+
29+
@pytest.mark.integration
30+
def test_auditlogs_send_to_udp_command_returns_success_return_code(
31+
runner, integration_test_profile, udp_dataserver
32+
):
33+
command = append_profile(
34+
f"audit-logs send-to localhost:5141 -p UDP -b '{begin_date_str}'"
35+
)
36+
result = runner.invoke(cli, split_command(command))
3137
assert result.exit_code == 0
3238

3339

tests/integration/test_securitydata.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,31 @@
44

55
import pytest
66
from tests.integration.conftest import append_profile
7-
from tests.integration.util import DataServer
87

98
from code42cli.main import cli
109

1110

1211
@pytest.mark.integration
13-
@pytest.mark.parametrize(
14-
"protocol", ["TCP", "UDP"],
15-
)
16-
def test_security_data_send_to_return_success_return_code(
17-
runner, integration_test_profile, protocol
12+
def test_security_data_send_to_tcp_return_success_return_code(
13+
runner, integration_test_profile, tcp_dataserver
1814
):
1915
begin_date = datetime.utcnow() - timedelta(days=20)
2016
begin_date_str = begin_date.strftime("%Y-%m-%d")
21-
command = "security-data send-to localhost:5140 -p {} -b {}".format(
22-
protocol, begin_date_str
17+
command = append_profile(
18+
f"security-data send-to localhost:5140 -p TCP -b '{begin_date_str}'"
2319
)
24-
with DataServer(protocol=protocol):
25-
result = runner.invoke(cli, split_command(append_profile(command)))
20+
result = runner.invoke(cli, split_command(command))
21+
assert result.exit_code == 0
22+
23+
24+
@pytest.mark.integration
25+
def test_security_data_send_to_udp_return_success_return_code(
26+
runner, integration_test_profile, udp_dataserver
27+
):
28+
begin_date = datetime.utcnow() - timedelta(days=20)
29+
begin_date_str = begin_date.strftime("%Y-%m-%d")
30+
command = append_profile(
31+
f"security-data send-to localhost:5141 -p UDP -b '{begin_date_str}'"
32+
)
33+
result = runner.invoke(cli, split_command(command))
2634
assert result.exit_code == 0

tests/integration/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def wrapper():
3838

3939
class DataServer:
4040
TCP_SERVER_COMMAND = "ncat -l 5140"
41-
UDP_SERVER_COMMAND = "ncat -ul 5140"
41+
UDP_SERVER_COMMAND = "ncat -ul 5141"
4242

4343
def __init__(self, protocol="TCP"):
4444
if protocol.upper() == "UDP":

0 commit comments

Comments
 (0)