xref: /unit/test/test_ruby_hooks.py (revision 2073:bc6ad31ce286)
11912So.canty@f5.comfrom unit.applications.lang.ruby import TestApplicationRuby
21912So.canty@f5.comfrom unit.option import option
31912So.canty@f5.comfrom unit.utils import waitforglob
41912So.canty@f5.com
51912So.canty@f5.com
61912So.canty@f5.comclass TestRubyHooks(TestApplicationRuby):
71912So.canty@f5.com    prerequisites = {'modules': {'ruby': 'all'}}
81912So.canty@f5.com
91912So.canty@f5.com    def _wait_cookie(self, pattern, count):
101912So.canty@f5.com        return waitforglob(
111912So.canty@f5.com            option.temp_dir + '/ruby/hooks/cookie_' + pattern, count
121912So.canty@f5.com        )
131912So.canty@f5.com
141912So.canty@f5.com    def test_ruby_hooks_eval(self):
151912So.canty@f5.com        processes = 2
161912So.canty@f5.com
171912So.canty@f5.com        self.load('hooks', processes=processes, hooks='eval.rb')
181912So.canty@f5.com
191912So.canty@f5.com        hooked = self._wait_cookie('eval.*', processes)
201912So.canty@f5.com
211912So.canty@f5.com        assert hooked, 'hooks evaluated'
221912So.canty@f5.com
231912So.canty@f5.com    def test_ruby_hooks_on_worker_boot(self):
241912So.canty@f5.com        processes = 2
251912So.canty@f5.com
261912So.canty@f5.com        self.load('hooks', processes=processes, hooks='on_worker_boot.rb')
271912So.canty@f5.com
281912So.canty@f5.com        hooked = self._wait_cookie('worker_boot.*', processes)
291912So.canty@f5.com
301912So.canty@f5.com        assert hooked, 'on_worker_boot called'
311912So.canty@f5.com
321912So.canty@f5.com    def test_ruby_hooks_on_worker_shutdown(self):
331912So.canty@f5.com        processes = 2
341912So.canty@f5.com
351912So.canty@f5.com        self.load('hooks', processes=processes, hooks='on_worker_shutdown.rb')
361912So.canty@f5.com
371912So.canty@f5.com        assert self.get()['status'] == 200, 'app response'
381912So.canty@f5.com
391912So.canty@f5.com        self.load('empty')
401912So.canty@f5.com
411912So.canty@f5.com        hooked = self._wait_cookie('worker_shutdown.*', processes)
421912So.canty@f5.com
431912So.canty@f5.com        assert hooked, 'on_worker_shutdown called'
441912So.canty@f5.com
451912So.canty@f5.com    def test_ruby_hooks_on_thread_boot(self):
461912So.canty@f5.com        processes = 1
471912So.canty@f5.com        threads = 2
481912So.canty@f5.com
491912So.canty@f5.com        self.load(
501912So.canty@f5.com            'hooks',
511912So.canty@f5.com            processes=processes,
521912So.canty@f5.com            threads=threads,
531912So.canty@f5.com            hooks='on_thread_boot.rb',
541912So.canty@f5.com        )
551912So.canty@f5.com
561912So.canty@f5.com        hooked = self._wait_cookie('thread_boot.*', processes * threads)
571912So.canty@f5.com
581912So.canty@f5.com        assert hooked, 'on_thread_boot called'
591912So.canty@f5.com
601912So.canty@f5.com    def test_ruby_hooks_on_thread_shutdown(self):
611912So.canty@f5.com        processes = 1
621912So.canty@f5.com        threads = 2
631912So.canty@f5.com
641912So.canty@f5.com        self.load(
651912So.canty@f5.com            'hooks',
661912So.canty@f5.com            processes=processes,
671912So.canty@f5.com            threads=threads,
681912So.canty@f5.com            hooks='on_thread_shutdown.rb',
691912So.canty@f5.com        )
701912So.canty@f5.com
711912So.canty@f5.com        assert self.get()['status'] == 200, 'app response'
721912So.canty@f5.com
731912So.canty@f5.com        self.load('empty')
741912So.canty@f5.com
751912So.canty@f5.com        hooked = self._wait_cookie('thread_shutdown.*', processes * threads)
761912So.canty@f5.com
771912So.canty@f5.com        assert hooked, 'on_thread_shutdown called'
781912So.canty@f5.com
791912So.canty@f5.com    def test_ruby_hooks_multiple(self):
801912So.canty@f5.com        processes = 1
811912So.canty@f5.com        threads = 1
821912So.canty@f5.com
831912So.canty@f5.com        self.load(
84*2073Szelenkov@nginx.com            'hooks',
85*2073Szelenkov@nginx.com            processes=processes,
86*2073Szelenkov@nginx.com            threads=threads,
87*2073Szelenkov@nginx.com            hooks='multiple.rb',
881912So.canty@f5.com        )
891912So.canty@f5.com
901912So.canty@f5.com        hooked = self._wait_cookie('worker_boot.*', processes)
911912So.canty@f5.com        assert hooked, 'on_worker_boot called'
921912So.canty@f5.com
931912So.canty@f5.com        hooked = self._wait_cookie('thread_boot.*', threads)
941912So.canty@f5.com        assert hooked, 'on_thread_boot called'
95