SF.net SVN: jython:[7216] trunk/jython/Lib/test/test_support.py
[email protected] Sat, 12 Mar 2011 18:54:26 +0000
| Newsgroups | gmane.comp.lang.jython.cvs |
|---|---|
| Message-ID | <[email protected]> |
Revision: 7216
http://jython.svn.sourceforge.net/jython/?rev=7216&view=rev
Author: fwierzbicki
Date: 2011-03-12 18:54:26 +0000 (Sat, 12 Mar 2011)
Log Message:
-----------
Fixes (not all of them good) to get test_support working for Jython.
Modified Paths:
--------------
trunk/jython/Lib/test/test_support.py
Modified: trunk/jython/Lib/test/test_support.py
===================================================================
--- trunk/jython/Lib/test/test_support.py 2011-03-12 18:46:20 UTC (rev 7215)
+++ trunk/jython/Lib/test/test_support.py 2011-03-12 18:54:26 UTC (rev 7216)
@@ -207,7 +207,34 @@
on Windows), it will be set on the socket. This will prevent anyone else
from bind()'ing to our host/port for the duration of the test.
"""
- if sock.family == socket.AF_INET and sock.type == socket.SOCK_STREAM:
+
+ #XXX: This section is probably wrong as I (Frank Wierzbicki) don't really
+ # understand it, but I needed this to get the asynchat tests running
+ # again.
+ if is_jython:
+ # Find some random ports that hopefully no one is listening on.
+ # Ideally each test would clean up after itself and not continue
+ # listening on any ports. However, this isn't the case. The last port
+ # (0) is a stop-gap that asks the O/S to assign a port. Whenever the
+ # warning message below is printed, the test that is listening on the
+ # port should be fixed to close the socket at the end of the test.
+ # Another reason why we can't use a port is another process (possibly
+ # another instance of the test suite) is using the same port.
+
+ for port in [54321, 9907, 10243, 32999, 0]:
+ try:
+ sock.bind((host, port))
+ if port == 0:
+ port = sock.getsockname()[1]
+ return port
+ except socket.error, (err, msg):
+ if err != errno.EADDRINUSE:
+ raise
+ print >>sys.__stderr__, \
+ ' WARNING: failed to listen on port %d, trying another' % port
+ raise TestFailed, 'unable to find port to listen on'
+
+ elif sock.family == socket.AF_INET and sock.type == socket.SOCK_STREAM:
if hasattr(socket, 'SO_REUSEADDR'):
if sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR) == 1:
raise TestFailed("tests should never set the SO_REUSEADDR " \
@@ -248,7 +275,25 @@
have_unicode = False
is_jython = sys.platform.startswith('java')
+if is_jython:
+ def make_jar_classloader(jar):
+ import os
+ from java.net import URL, URLClassLoader
+ url = URL('jar:file:%s!/' % jar)
+ if os._name == 'nt':
+ # URLJarFiles keep a cached open file handle to the jar even
+ # after this ClassLoader is GC'ed, disallowing Windows tests
+ # from removing the jar file from disk when finished with it
+ conn = url.openConnection()
+ if conn.getDefaultUseCaches():
+ # XXX: Globally turn off jar caching: this stupid
+ # instance method actually toggles a static flag. Need a
+ # better fix
+ conn.setDefaultUseCaches(False)
+
+ return URLClassLoader([url])
+
# Filename used for testing
if os.name == 'java':
# Jython disallows @ in module names
@@ -857,6 +902,8 @@
def threading_setup():
import threading
+ if is_jython:
+ return len(threading._active), 0
return len(threading._active), len(threading._limbo)
def threading_cleanup(num_active, num_limbo):
@@ -869,10 +916,11 @@
count += 1
time.sleep(0.1)
- count = 0
- while len(threading._limbo) != num_limbo and count < _MAX_COUNT:
- count += 1
- time.sleep(0.1)
+ if not is_jython:
+ count = 0
+ while len(threading._limbo) != num_limbo and count < _MAX_COUNT:
+ count += 1
+ time.sleep(0.1)
def reap_children():
"""Use this function at the end of test_main() whenever sub-processes
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d