1import time 2 3import pytest 4from unit.applications.proto import TestApplicationProto 5 6 7class TestReconfigure(TestApplicationProto): 8 prerequisites = {} 9 10 @pytest.fixture(autouse=True) 11 def setup_method_fixture(self): 12 assert 'success' in self.conf( 13 { 14 "listeners": {"*:7080": {"pass": "routes"}}, 15 "routes": [{"action": {"return": 200}}], 16 "applications": {}, 17 } 18 ) 19 20 def clear_conf(self): 21 assert 'success' in self.conf({"listeners": {}, "applications": {}}) 22 23 def test_reconfigure(self): 24 (_, sock) = self.http( 25 b"""GET / HTTP/1.1 26""", 27 start=True, 28 raw=True, 29 no_recv=True, 30 ) 31 32 self.clear_conf() 33 34 resp = self.http( 35 b"""Host: localhost 36Connection: close 37 38""", 39 sock=sock, 40 raw=True, 41 ) 42 assert resp['status'] == 200, 'finish request' 43 44 def test_reconfigure_2(self): 45 (_, sock) = self.http(b'', raw=True, start=True, no_recv=True) 46 47 # Waiting for connection completion. 48 # Delay should be more than TCP_DEFER_ACCEPT. 49 time.sleep(1.5) 50 51 self.clear_conf() 52 53 assert self.get(sock=sock)['status'] == 408, 'request timeout' 54