repository: make tests pass again
The tests use mono-threaded pyro, which breaks assumptions made in
e27337dfec8c. To fix that, remove sessions from the _pyro_sessions dict
when they're closed, and force the test pyro client to actually
disconnect when it's done.
--- a/server/repository.py Wed Jun 12 18:33:50 2013 +0200
+++ b/server/repository.py Fri Jun 14 11:53:40 2013 +0200
@@ -885,6 +885,8 @@
# during `session_close` hooks
session.commit()
session.close()
+ if threading.currentThread() in self._pyro_sessions:
+ self._pyro_sessions[threading.currentThread()] = None
del self._sessions[sessionid]
self.info('closed session %s for user %s', sessionid, session.user.login)
@@ -1654,10 +1656,7 @@
daemon.getAdapter().handleConnection = handleConnection
def removeConnection(conn, sessions=pyro_sessions):
daemon.__class__.removeConnection(daemon, conn)
- try:
- session = sessions[threading.currentThread()]
- except KeyError:
- return
+ session = sessions.pop(threading.currentThread(), None)
if session is None:
# client was not yet connected to the repo
return
--- a/server/test/unittest_repository.py Wed Jun 12 18:33:50 2013 +0200
+++ b/server/test/unittest_repository.py Fri Jun 14 11:53:40 2013 +0200
@@ -349,7 +349,10 @@
self.assertTrue(user._cw.vreg)
from cubicweb.entities import authobjs
self.assertIsInstance(user._cw.user, authobjs.CWUser)
+ # make sure the tcp connection is closed properly; yes, it's disgusting.
+ adapter = cnx._repo.adapter
cnx.close()
+ adapter.release()
done.append(True)
finally:
# connect monkey patch some method by default, remove them