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