Commit 1cc0e6b4 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Bug fix: Queued events must have the right peer id on their connection.

When called, queued events were using the last peer message id instead of
having the good one on their connection when recalled, so answers made from
queued events was using the wrong message id.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1866 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 3ab6e541
...@@ -263,15 +263,17 @@ class Application(object): ...@@ -263,15 +263,17 @@ class Application(object):
if not node.isHidden(): if not node.isHidden():
break break
def queueEvent(self, some_callable, *args, **kwargs): def queueEvent(self, some_callable, conn, *args, **kwargs):
self.event_queue.append((some_callable, args, kwargs)) msg_id = conn.getPeerId()
self.event_queue.append((some_callable, msg_id, conn, args, kwargs))
def executeQueuedEvents(self): def executeQueuedEvents(self):
l = len(self.event_queue) l = len(self.event_queue)
p = self.event_queue.popleft p = self.event_queue.popleft
for i in xrange(l): for i in xrange(l):
some_callable, args, kwargs = p() some_callable, msg_id, conn, args, kwargs = p()
some_callable(*args, **kwargs) conn.setPeerId(msg_id)
some_callable(conn, *args, **kwargs)
def shutdown(self, erase=False): def shutdown(self, erase=False):
"""Close all connections and exit""" """Close all connections and exit"""
......
...@@ -122,23 +122,27 @@ class StorageAppTests(NeoTestBase): ...@@ -122,23 +122,27 @@ class StorageAppTests(NeoTestBase):
def test_02_queueEvent(self): def test_02_queueEvent(self):
self.assertEqual(len(self.app.event_queue), 0) self.assertEqual(len(self.app.event_queue), 0)
event = Mock({"getId": 1325136}) msg_id = 1325136
self.app.queueEvent(event, "test", key="value") event = Mock({'__repr__': 'event'})
conn = Mock({'__repr__': 'conn', 'getPeerId': msg_id})
self.app.queueEvent(event, conn, "test", key="value")
self.assertEqual(len(self.app.event_queue), 1) self.assertEqual(len(self.app.event_queue), 1)
event, args, kw = self.app.event_queue[0] _event, _msg_id, _conn, args, kw = self.app.event_queue[0]
self.assertEqual(event.getId(), 1325136) self.assertEqual(msg_id, _msg_id)
self.assertEqual(len(args), 1) self.assertEqual(len(args), 1)
self.assertEqual(args[0], "test") self.assertEqual(args[0], "test")
self.assertEqual(kw, {"key" : "value"}) self.assertEqual(kw, {"key" : "value"})
def test_03_executeQueuedEvents(self): def test_03_executeQueuedEvents(self):
self.assertEqual(len(self.app.event_queue), 0) self.assertEqual(len(self.app.event_queue), 0)
event = Mock({"getId": 1325136}) msg_id = 1325136
self.app.queueEvent(event, "test", key="value") event = Mock({'__repr__': 'event'})
conn = Mock({'__repr__': 'conn', 'getPeerId': msg_id})
self.app.queueEvent(event, conn, "test", key="value")
self.app.executeQueuedEvents() self.app.executeQueuedEvents()
self.assertEquals(len(event.mockGetNamedCalls("__call__")), 1) self.assertEquals(len(event.mockGetNamedCalls("__call__")), 1)
call = event.mockGetNamedCalls("__call__")[0] call = event.mockGetNamedCalls("__call__")[0]
params = call.getParam(0) params = call.getParam(1)
self.assertEqual(params, "test") self.assertEqual(params, "test")
params = call.kwparams params = call.kwparams
self.assertEqual(params, {'key': 'value'}) self.assertEqual(params, {'key': 'value'})
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment