Rev 4887: Try to test _flush. in http://bazaar.launchpad.net/~jameinel/bzr/2.1-client-reconnect-819604
John Arbash Meinel
john at arbash-meinel.com
Wed Sep 28 14:55:49 UTC 2011
At http://bazaar.launchpad.net/~jameinel/bzr/2.1-client-reconnect-819604
------------------------------------------------------------
revno: 4887
revision-id: john at arbash-meinel.com-20110928145536-rahm8funuc23vfr4
parent: john at arbash-meinel.com-20110928144438-hr8f61f2o73hek85
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1-client-reconnect-819604
timestamp: Wed 2011-09-28 16:55:36 +0200
message:
Try to test _flush.
On Windows, with buffered files, things hang, so don't do that.
With an unbuffered pipe, we seem to get the same results as
subprocess.Popen, which is that handle.flush() is a no-op.
(Even though the reader is closed by that point, and we
haven't read the bites that were already written, flush
doesn't raise an error.)
-------------- next part --------------
=== modified file 'bzrlib/tests/test_smart_transport.py'
--- a/bzrlib/tests/test_smart_transport.py 2011-09-28 14:44:38 +0000
+++ b/bzrlib/tests/test_smart_transport.py 2011-09-28 14:55:36 +0000
@@ -53,6 +53,7 @@
def create_file_pipes():
r, w = os.pipe()
+ # These must be opened without buffering, or we get undefined results
rf = os.fdopen(r, 'rb', 0)
wf = os.fdopen(w, 'wb', 0)
return rf, wf
@@ -206,8 +207,8 @@
child_read, client_write = create_file_pipes()
client_medium = medium.SmartSimplePipesClientMedium(
None, client_write, 'base')
- client_medium._accept_bytes('abc')
- self.assertEqual('abc', child_read.read(3))
+ client_medium._accept_bytes('abc\n')
+ self.assertEqual('abc\n', child_read.read(4))
# While writing to the underlying pipe,
# Windows py2.6.6 we get IOError(EINVAL)
# Lucid py2.6.5, we get IOError(EPIPE)
@@ -216,6 +217,29 @@
self.assertRaises(errors.ConnectionReset,
client_medium._accept_bytes, 'more')
+ def test_simple_pipes__flush_pipe_closed(self):
+ child_read, client_write = create_file_pipes()
+ client_medium = medium.SmartSimplePipesClientMedium(
+ None, client_write, 'base')
+ client_medium._accept_bytes('abc\n')
+ child_read.close()
+ # Even though the pipe is closed, flush on the write side seems to be a
+ # no-op, rather than a failure.
+ client_medium._flush()
+
+ def test_simple_pipes__flush_subprocess_closed(self):
+ p = subprocess.Popen([sys.executable, '-c',
+ 'import sys\n'
+ 'sys.stdout.write(sys.stdin.read(4))\n'
+ 'sys.stdout.close()\n'],
+ stdout=subprocess.PIPE, stdin=subprocess.PIPE)
+ client_medium = medium.SmartSimplePipesClientMedium(
+ p.stdout, p.stdin, 'base')
+ client_medium._accept_bytes('abc\n')
+ p.wait()
+ # Even though the child process is dead, flush seems to be a no-op.
+ client_medium._flush()
+
def test_simple_pipes_client_disconnect_does_nothing(self):
# calling disconnect does nothing.
input = StringIO()
More information about the bazaar-commits
mailing list