def test_open_first_fork_child_second_fork_parent(self): self.os_mock.fork = MagicMock(side_effect=[0, 1123]) self.os_mock._exit.side_effect = LowLevelExit self.daemoncontext.pidfile = Mock() self.daemoncontext.signal_map = { self.signal_mock.SIGTSTP: None, self.signal_mock.SIGTTIN: None, self.signal_mock.SIGTTOU: None, self.signal_mock.SIGTERM: 'terminate'} with self.assertRaises(LowLevelExit) as err: self.daemoncontext.open() self.os_mock.assert_has_calls( [call.getuid(), call.getgid(), call.chdir('/'), call.setgid(54321), call.setuid(12345), call.umask(0), call.fork(), call.setsid(), call.fork()]) self.resource_mock.assert_has_calls( [call.setrlimit(self.resource_mock.RLIMIT_CORE, (0, 0))])
def test_open_first_fork_child_second_fork_child(self): self.os_mock.fork = MagicMock(side_effect=[0, 0]) self.daemoncontext.pidfile = Mock() terminate = getattr(self.daemoncontext, 'terminate') self.daemoncontext.signal_map = { self.signal_mock.SIGTSTP: None, self.signal_mock.SIGTTIN: None, self.signal_mock.SIGTTOU: None, self.signal_mock.SIGTERM: 'terminate' } self.daemoncontext.open() self.os_mock.assert_has_calls([ call.getuid(), call.getgid(), call.chdir('/'), call.setgid(54321), call.setuid(12345), call.umask(0), call.fork(), call.setsid(), call.fork(), call.close(0), call.open(self.os_mock.devnull, self.os_mock.O_RDWR), call.dup2(self.os_mock.open(), self.sys_mock.stdin.fileno()), call.open(self.os_mock.devnull, self.os_mock.O_RDWR), call.dup2(self.os_mock.open(), self.sys_mock.stdout.fileno()), call.open(self.os_mock.devnull, self.os_mock.O_RDWR), call.dup2(self.os_mock.open(), self.sys_mock.stderr.fileno()) ]) self.resource_mock.assert_has_calls([ call.setrlimit(self.resource_mock.RLIMIT_CORE, (0, 0)), call.getrlimit(2048) ]) self.signal_mock.assert_has_calls([ call.signal(self.signal_mock.SIGTSTP, self.signal_mock.SIG_IGN), call.signal(self.signal_mock.SIGTERM, terminate), call.signal(self.signal_mock.SIGTTIN, self.signal_mock.SIG_IGN), call.signal(self.signal_mock.SIGTTOU, self.signal_mock.SIG_IGN) ], any_order=True) self.sys_mock.assert_has_calls([ call.stdin.fileno(), call.stdout.fileno(), call.stderr.fileno(), call.stdin.fileno(), call.stdout.fileno(), call.stderr.fileno() ])
def test_open_first_fork_child_second_fork_child_and_pitfile(self): self.os_mock.fork = MagicMock(side_effect=[0, 0]) self.daemoncontext.pidfile = Mock() terminate = getattr(self.daemoncontext, 'terminate') self.daemoncontext.signal_map = { self.signal_mock.SIGTSTP: None, self.signal_mock.SIGTTIN: None, self.signal_mock.SIGTTOU: None, self.signal_mock.SIGTERM: 'terminate'} self.daemoncontext.open() self.os_mock.assert_has_calls( [call.getuid(), call.getgid(), call.chdir('/'), call.setgid(54321), call.setuid(12345), call.umask(0), call.fork(), call.setsid(), call.fork(), call.close(0), call.open(self.os_mock.devnull, self.os_mock.O_RDWR), call.dup2(self.os_mock.open(), self.sys_mock.stdin.fileno()), call.open(self.os_mock.devnull, self.os_mock.O_RDWR), call.dup2(self.os_mock.open(), self.sys_mock.stdout.fileno()), call.open(self.os_mock.devnull, self.os_mock.O_RDWR), call.dup2(self.os_mock.open(), self.sys_mock.stderr.fileno())]) self.resource_mock.assert_has_calls( [call.setrlimit(self.resource_mock.RLIMIT_CORE, (0, 0)), call.getrlimit(2048)]) self.signal_mock.assert_has_calls( [call.signal(self.signal_mock.SIGTSTP, self.signal_mock.SIG_IGN), call.signal(self.signal_mock.SIGTERM, terminate), call.signal(self.signal_mock.SIGTTIN, self.signal_mock.SIG_IGN), call.signal(self.signal_mock.SIGTTOU, self.signal_mock.SIG_IGN)], any_order=True) self.sys_mock.assert_has_calls( [call.stdin.fileno(), call.stdout.fileno(), call.stderr.fileno(), call.stdin.fileno(), call.stdout.fileno(), call.stderr.fileno()]) self.daemoncontext.pidfile.assert_has_calls( [call.acquire()] )