[PATCH] test-http-proxy: partially adapt for MSYS on Windows

Adrian Buehlmann adrian at cadifra.com
Sat Jun 30 13:27:47 CDT 2012


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1341078654 -7200
# Node ID babcc6c75b73942c943904af0efa1d4a73c777ea
# Parent  c91158921e6472da7a090933b5ce2154a1ba46e9
test-http-proxy: partially adapt for MSYS on Windows

Redirection with ">proxy.log 2>&1" failed to work as expected in sh.exe of MSYS.
When run in an interactive shell, stderr output was printed to the terminal, no
matter what I tried.

Using "&>proxy.log" proved to be working, but additionally requires to flush
stderr in tinyproxy.py.

However, using "&>proxy.log" causes the test to hang on Linux, so I keep the
original procedure for non-windows.

The "Connection refused" case requires special handling for Windows, as the test
otherwise would fail with

     $ http_proxy=localhost:$HGPORT2 hg clone --config http_proxy.always=True http://localhost:$HGPORT/ f
  -  abort: error: Connection refused
  +  abort: error: No connection could be made because the target machine actively refused it
     [255]

Since the error message on Windows could be in any language, I'm (glob)-ing the
entire error message away for Windows. I keep the no-windows error message
precisely as it is, as this is nice to have for reference, so we see what is
expected there. On non-windows, there doesn't seem to be that much of a problem
with translated error messages.

The adaption is partial, because "serve" is not yet officially supported in
in tests on Windows.

The test passes on Windows with an experimental testbed that supports
"hg serve" in tests on Windows.

diff --git a/tests/test-http-proxy.t b/tests/test-http-proxy.t
--- a/tests/test-http-proxy.t
+++ b/tests/test-http-proxy.t
@@ -8,7 +8,11 @@
   $ hg --config server.uncompressed=True serve -p $HGPORT -d --pid-file=hg.pid
   $ cat hg.pid >> $DAEMON_PIDS
   $ cd ..
+#if no-windows
   $ "$TESTDIR/tinyproxy.py" $HGPORT1 localhost >proxy.log 2>&1 </dev/null &
+#else
+  $ "$TESTDIR/tinyproxy.py" $HGPORT1 localhost &>proxy.log </dev/null &
+#endif
   $ while [ ! -f proxy.pid ]; do sleep 0; done
   $ cat proxy.pid >> $DAEMON_PIDS
 
@@ -83,9 +87,15 @@
 
 bad host:port for proxy
 
+#if no-windows
   $ http_proxy=localhost:$HGPORT2 hg clone --config http_proxy.always=True http://localhost:$HGPORT/ f
   abort: error: Connection refused
   [255]
+#else
+  $ http_proxy=localhost:$HGPORT2 hg clone --config http_proxy.always=True http://localhost:$HGPORT/ f
+  abort: * (glob)
+  [255]
+#endif
 
 do not use the proxy if it is in the no list
 
diff --git a/tests/tinyproxy.py b/tests/tinyproxy.py
--- a/tests/tinyproxy.py
+++ b/tests/tinyproxy.py
@@ -12,7 +12,7 @@
 
 __version__ = "0.2.1"
 
-import BaseHTTPServer, select, socket, SocketServer, urlparse, os
+import BaseHTTPServer, select, socket, SocketServer, urlparse, os, sys
 
 class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler):
     __base = BaseHTTPServer.BaseHTTPRequestHandler
@@ -36,6 +36,7 @@
         self.log_message('"%s" %s %s%s',
                          self.requestline, str(code), str(size),
                          ''.join([' %s:%s' % h for h in sorted(xheaders)]))
+        sys.stderr.flush()
 
     def _connect_to(self, netloc, soc):
         i = netloc.find(':')


More information about the Mercurial-devel mailing list