From 2f0cca2e2b48f3f96056bac14e216f1248f8d4a8 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Tue, 18 May 2021 16:35:54 +0100 Subject: [PATCH] Tests: added test to check port release. --- test/test_configuration.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/test_configuration.py b/test/test_configuration.py index 7feb3adb..880aef6c 100644 --- a/test/test_configuration.py +++ b/test/test_configuration.py @@ -1,5 +1,6 @@ import pytest +import socket from unit.control import TestControl @@ -261,6 +262,33 @@ class TestConfiguration(TestControl): } ), 'explicit ipv6' + def test_listeners_port_release(self): + for i in range(10): + fail = False + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + + self.conf( + { + "listeners": {"127.0.0.1:7080": {"pass": "routes"}}, + "routes": [], + } + ) + + resp = self.conf({"listeners": {}, "applications": {}}) + + try: + s.bind(('127.0.0.1', 7080)) + s.listen() + + except OSError: + fail = True + + if fail: + pytest.fail('cannot bind or listen to the address') + + assert 'success' in resp, 'port release' + @pytest.mark.skip('not yet, unsafe') def test_listeners_no_port(self): assert 'error' in self.conf(