xref: /unit/test/test_ruby_hooks.py (revision 1984:06514cd08a35)
1from unit.applications.lang.ruby import TestApplicationRuby
2from unit.option import option
3from unit.utils import waitforglob
4
5
6class TestRubyHooks(TestApplicationRuby):
7    prerequisites = {'modules': {'ruby': 'all'}}
8
9    def _wait_cookie(self, pattern, count):
10        return waitforglob(
11            option.temp_dir + '/ruby/hooks/cookie_' + pattern, count
12        )
13
14    def test_ruby_hooks_eval(self):
15        processes = 2
16
17        self.load('hooks', processes=processes, hooks='eval.rb')
18
19        hooked = self._wait_cookie('eval.*', processes)
20
21        assert hooked, 'hooks evaluated'
22
23    def test_ruby_hooks_on_worker_boot(self):
24        processes = 2
25
26        self.load('hooks', processes=processes, hooks='on_worker_boot.rb')
27
28        hooked = self._wait_cookie('worker_boot.*', processes)
29
30        assert hooked, 'on_worker_boot called'
31
32    def test_ruby_hooks_on_worker_shutdown(self):
33        processes = 2
34
35        self.load('hooks', processes=processes, hooks='on_worker_shutdown.rb')
36
37        assert self.get()['status'] == 200, 'app response'
38
39        self.load('empty')
40
41        hooked = self._wait_cookie('worker_shutdown.*', processes)
42
43        assert hooked, 'on_worker_shutdown called'
44
45    def test_ruby_hooks_on_thread_boot(self):
46        processes = 1
47        threads = 2
48
49        self.load(
50            'hooks',
51            processes=processes,
52            threads=threads,
53            hooks='on_thread_boot.rb',
54        )
55
56        hooked = self._wait_cookie('thread_boot.*', processes * threads)
57
58        assert hooked, 'on_thread_boot called'
59
60    def test_ruby_hooks_on_thread_shutdown(self):
61        processes = 1
62        threads = 2
63
64        self.load(
65            'hooks',
66            processes=processes,
67            threads=threads,
68            hooks='on_thread_shutdown.rb',
69        )
70
71        assert self.get()['status'] == 200, 'app response'
72
73        self.load('empty')
74
75        hooked = self._wait_cookie('thread_shutdown.*', processes * threads)
76
77        assert hooked, 'on_thread_shutdown called'
78
79    def test_ruby_hooks_multiple(self):
80        processes = 1
81        threads = 1
82
83        self.load(
84            'hooks', processes=processes, threads=threads, hooks='multiple.rb',
85        )
86
87        hooked = self._wait_cookie('worker_boot.*', processes)
88        assert hooked, 'on_worker_boot called'
89
90        hooked = self._wait_cookie('thread_boot.*', threads)
91        assert hooked, 'on_thread_boot called'
92