diff options
author | Douglas Turk <dougturk@google.com> | 2012-09-03 14:48:00 +1000 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2012-09-24 18:58:54 -0700 |
commit | 681a465f327a4986c9b7232dd28e2eca7392a6f2 (patch) | |
tree | 99db3412f0563deb0301a4ad0922f6f4b50c86a0 /tests | |
parent | 7ead8d9c70ab81023e2a0c37e0f3ab7ebf9814af (diff) |
Handle/fix handling of EINTR errors in a few places.
(cherry picked from commit 351bdb72e539c373985e108c89f61839f3acdd2a)
Conflicts:
paramiko/agent.py
paramiko/client.py
paramiko/transport.py
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_util.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/test_util.py b/tests/test_util.py index ed0607fa..59a3d99e 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -22,6 +22,7 @@ Some unit tests for utility functions. from binascii import hexlify import cStringIO +import errno import os import unittest from Crypto.Hash import SHA @@ -177,3 +178,28 @@ Host * ssh.util.lookup_ssh_host_config(host, config), {'hostname': host, 'port': '22'} ) + + def test_8_eintr_retry(self): + self.assertEquals('foo', ssh.util.retry_on_signal(lambda: 'foo')) + + # Variables that are set by raises_intr + intr_errors_remaining = [3] + call_count = [0] + def raises_intr(): + call_count[0] += 1 + if intr_errors_remaining[0] > 0: + intr_errors_remaining[0] -= 1 + raise IOError(errno.EINTR, 'file', 'interrupted system call') + self.assertTrue(ssh.util.retry_on_signal(raises_intr) is None) + self.assertEquals(0, intr_errors_remaining[0]) + self.assertEquals(4, call_count[0]) + + def raises_ioerror_not_eintr(): + raise IOError(errno.ENOENT, 'file', 'file not found') + self.assertRaises(IOError, + lambda: ssh.util.retry_on_signal(raises_ioerror_not_eintr)) + + def raises_other_exception(): + raise AssertionError('foo') + self.assertRaises(AssertionError, + lambda: ssh.util.retry_on_signal(raises_other_exception)) |