Skip to content

Commit 691de96

Browse files
committed
hacky way for messagebus to return results
1 parent 41bf20b commit 691de96

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/allocation/messagebus.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@
44

55

66
def handle(events_: List[events.Event], uow: unit_of_work.AbstractUnitOfWork):
7+
results = []
78
while events_:
89
event = events_.pop(0)
10+
print('handling message', event, flush=True)
911
for handler in HANDLERS[type(event)]:
10-
handler(event, uow=uow)
12+
r = handler(event, uow=uow)
13+
print('got result', r, flush=True)
14+
results.append(r)
15+
return results
1116

1217

1318
HANDLERS = {

tests/unit/test_handlers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ class TestAllocate:
6969
@staticmethod
7070
def test_returns_allocation():
7171
uow = FakeUnitOfWork()
72-
result = messagebus.handle([
72+
results = messagebus.handle([
7373
events.BatchCreated("b1", "COMPLICATED-LAMP", 100, None),
74-
events.AllocationRequest("o1", "COMPLICATED-LAMP", 10 )
74+
events.AllocationRequest("o1", "COMPLICATED-LAMP", 10),
7575
], uow)
76-
assert result == "b1"
76+
assert results.pop() == "b1"
7777

7878
@staticmethod
7979
def test_errors_for_invalid_sku():
@@ -85,7 +85,6 @@ def test_errors_for_invalid_sku():
8585
events.AllocationRequest("o1", "NONEXISTENTSKU", 10)
8686
], uow)
8787

88-
8988
@staticmethod
9089
def test_commits():
9190
uow = FakeUnitOfWork()

0 commit comments

Comments
 (0)