Changeset a7d09
- Timestamp:
- 03/04/10 09:15:36 (2 years ago)
- Branches:
- connections
- Parents:
- 8a171
- git-author:
- dthomp <dthompso@…> (03/04/10 09:15:36)
- git-committer:
- dthomp <dthompso@…> (03/04/10 09:15:36)
- Location:
- plasma
- Files:
-
- 2 edited
-
connections/memory_connection_manager.py (modified) (3 diffs)
-
test/connections/test_connection_manager.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
plasma/connections/memory_connection_manager.py
r8a171 ra7d09 1 1 import time 2 3 from twisted.internet import defer, reactor 2 4 3 5 from connection import Connection … … 83 85 """ 84 86 if id in self._connections: 85 if self._conne tions[id]['last_active'] < cutoff:87 if self._connections[id]['last_active'] < cutoff: 86 88 self.delete(id) 87 89 … … 102 104 # another function changes self._connections. 103 105 iter = self._connections.keys().__iter__() 104 106 d = defer.Deferred() 105 107 def _cleanLater(): 106 108 try: 107 109 id = iter.next() 108 110 self.clean(id, cutoff) 109 defer.callLater(0, _cleanLater)111 reactor.callLater(0, _cleanLater) 110 112 except StopIteration: 113 d.callback(None) 111 114 pass 112 115 113 _cleanLater() 116 reactor.callLater(0, _cleanLater) 117 return d -
plasma/test/connections/test_connection_manager.py
r8a171 ra7d09 1 import time 2 1 3 from twisted.internet import defer 2 4 from twisted.trial import unittest … … 75 77 76 78 def test_clean(self): 77 pass 79 id = 'new id' 80 def _assertConnectionNotFound(failure): 81 self.assertIsInstance(failure.value, ConnectionNotFoundError) 82 83 def _assertCleaned(result, id): 84 d = defer.maybeDeferred(self.manager.load, id) 85 d.addCallback(self.failCallback, "Connection not cleaned.") 86 d.addErrback(_assertConnectionNotFound) 87 88 def _clean(result, connection): 89 time.sleep(1) 90 d = defer.maybeDeferred(self.manager.clean, connection.id, time.time()) 91 d.addCallback(_assertCleaned, connection.id) 92 93 def _saveConnection(connection): 94 d = defer.maybeDeferred(self.manager.save, connection) 95 d.addCallback(_clean, connection) 96 97 d = self.manager.get(id) 98 d.addCallback(_saveConnection) 78 99 79 100 def test_cleanAll(self): 80 pass 101 id = 'new id' 102 103 def _assertConnectionNotFound(failure): 104 self.assertIsInstance(failure.value, ConnectionNotFoundError) 105 106 def _assertCleaned(result, id): 107 d = defer.maybeDeferred(self.manager.load, id) 108 d.addCallback(self.failCallback, "Connection not cleaned.") 109 d.addErrback(_assertConnectionNotFound) 110 111 def _cleanAll(result, connection): 112 time.sleep(1) 113 d = defer.maybeDeferred(self.manager.cleanAll, time.time()) 114 d.addCallback(_assertCleaned, connection.id) 115 116 def _saveConnection(connection): 117 d = defer.maybeDeferred(self.manager.save, connection) 118 d.addCallback(_cleanAll, connection) 119 120 d = self.manager.get(id) 121 d.addCallback(_saveConnection)
Note: See TracChangeset
for help on using the changeset viewer.