Permalink
Browse files

correct event count, wait() return value.

  • Loading branch information...
1 parent 3af4b83 commit 8eadd0ad3f4ac88eaace1b166680df35a875e928 @nakagami committed May 26, 2012
Showing with 30 additions and 22 deletions.
  1. +12 −12 firebirdsql/fbcore.py
  2. +18 −10 tests/tests_event.py
View
@@ -647,31 +647,31 @@ def __init__(self, conn, names):
for name in names:
self.event_names[name] = 0
- def wait(self):
- r = {}
(h, port, family, ip_address) = self.connection._op_connect_request()
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.connect((ip_address, port))
-
self.connection.last_event_id += 1
- self.connection._op_que_events(self.event_names,
- 0, 0, self.connection.last_event_id)
+ self.event_id = self.connection.last_event_id
+
+ self.connection._op_que_events(self.event_names, 0, 0, self.event_id)
(h, oid, buf) = self.connection._op_response()
- self.event_id = h
(event_id, event_names) = self._wait_for_event()
+ assert event_id == self.event_id # treat only one event_id
self.event_names.update(event_names)
- self.connection.last_event_id += 1
- self.connection._op_que_events(self.event_names,
- 0, 0, self.connection.last_event_id)
+ def wait(self):
+ self.connection._op_que_events(self.event_names, 0, 0, self.event_id)
(h, oid, buf) = self.connection._op_response()
- self.event_id = h
- self.connection.last_event_id += 1
(event_id, event_names) = self._wait_for_event()
+ assert event_id == self.event_id # treat only one event_id
- return (event_id, event_names)
+ r = {}
+ for k in event_names:
+ r[k] = event_names[k]-self.event_names[k]
+ self.event_names[k] = event_names[k]
+ return r
def close(self):
self.connection._op_cancel_events(self.event_id)
View
@@ -42,24 +42,32 @@ def create():
END''')
conn.commit()
-def handler():
+def produce():
+ conn = connect(dsn=TEST_DSN, user=TEST_USER, password=TEST_PASS)
+ conn.cursor().execute('insert into test_table values (1)')
+ conn.commit()
+
+
+def handle_event():
conn = connect(dsn=TEST_DSN, user=TEST_USER, password=TEST_PASS)
conduit = conn.event_conduit(['event_a', 'event_b', 'event_d'])
+
result = conduit.wait()
- print('HANDLER: An event notification has arrived:')
- print(result)
- conduit.close()
+ print('event has arrived 1:', result)
+ assert result == {'event_b': 1, 'event_a': 2, 'event_d': 0}
-def producer():
- conn = connect(dsn=TEST_DSN, user=TEST_USER, password=TEST_PASS)
- conn.cursor().execute('insert into test_table values (1)')
- conn.commit()
+ produce()
+ result = conduit.wait()
+ print('event has arrived 2:', result)
+ assert result == {'event_b': 1, 'event_a': 2, 'event_d': 0}
+
+ conduit.close()
if __name__ == '__main__':
create()
pid = os.fork()
if pid == 0:
- handler()
+ handle_event()
else:
time.sleep(1)
- producer()
+ produce()

0 comments on commit 8eadd0a

Please sign in to comment.