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 raw=True, 28 no_recv=True, 29 ) 30 31 self.clear_conf() 32 33 resp = self.http( 34 b"""Host: localhost 35Connection: close 36 37""", 38 sock=sock, 39 raw=True, 40 ) 41 assert resp['status'] == 200, 'finish request' 42 43 def test_reconfigure_2(self): 44 sock = self.http(b'', raw=True, no_recv=True) 45 46 # Waiting for connection completion. 47 # Delay should be more than TCP_DEFER_ACCEPT. 48 time.sleep(1.5) 49 50 self.clear_conf() 51 52 assert self.get(sock=sock)['status'] == 408, 'request timeout' 53