def test_acquire_exhausted(self): self.pool.pool_size = 1 self.pool._pool_used.add('a Connection') self.pool._lock = Mock() self.assertRaises(pyredis.exceptions.PyRedisError, self.pool.acquire) self.pool._lock.assert_has_calls([call.acquire(), call.release()])
def test_acquire_exhausted(self): self.pool.pool_size = 1 self.pool._pool_used.add("a Connection") self.pool._lock = Mock() self.assertRaises(pyredis.connection.PyRedisError, self.pool.acquire) self.pool._lock.assert_has_calls([call.acquire(), call.release()])
def test_acquire_free(self): client_orig = Mock() self.pool._pool_free.add(client_orig) self.pool._lock = Mock() client = self.pool.acquire() self.assertEqual(client_orig, client) self.pool._lock.assert_has_calls([call.acquire(), call.release()]) self.assertNotIn(client_orig, self.pool._pool_free) self.assertIn(client_orig, self.pool._pool_used)
def test_acquire_nonfree(self): client_orig = Mock() self.pool._connect = Mock() self.pool._connect.side_effect = [client_orig] self.pool._lock = Mock() client = self.pool.acquire() self.assertEqual(client_orig, client) self.pool._lock.assert_has_calls([call.acquire(), call.release()]) self.assertIn(client_orig, self.pool._pool_used)
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()])
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()] )