Skip to content

Commit

Permalink
Fixes #151: Send messages only when there is credit to send instead o… (
Browse files Browse the repository at this point in the history
#1282)

* Fixes #151: Send messages only when there is credit to send instead of sending all messages in one single loop. This makes sure that we are not exhausting credit inside the send loop

* Python checker errors
  • Loading branch information
ganeshmurthy authored Nov 1, 2023
1 parent 3c18462 commit 71e7c08
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions tests/system_tests_delivery_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,9 @@ def __init__(self, router_addr, count=None, rx_limit=None,
self.receiver = None
self.max_attempts = 10
self.num_attempts = 0
self.poll_timer_started = False
self.n_accepted = 0
self.n_released = 0

def timeout(self):
self._cleanup()
Expand Down Expand Up @@ -935,7 +938,9 @@ def on_start(self, event):
name="Tx_Test01")

def on_sendable(self, event):
while self.sent < self.count:
# Don't send all messages in one single loop.
# on_sendable is called only when there is credit, so send a message when there is credit.
if self.sent < self.count:
if self.large_message:
dlv = self.sender.send(Message(body=LARGE_PAYLOAD))
else:
Expand All @@ -944,19 +949,37 @@ def on_sendable(self, event):
dlv.settle()
self.sent += 1

# Start up a poll timer once all the deliveries have been sent/received.
if self.received == self.rx_limit and self.sent == self.count and not self.poll_timer_started and self.outcome is None:
self.poll_timer_started = True
self.poll_timer = event.reactor.schedule(0.5, PollTimeout(self))

def on_message(self, event):
self.received += 1
if self.outcome:
event.delivery.update(self.outcome)
event.delivery.settle()

# Start up a poll timer once all the deliveries have been sent/received.
if self.received == self.rx_limit and self.sent == self.count:
if self.received == self.rx_limit and self.sent == self.count and not self.poll_timer_started and self.outcome is None:
self.poll_timer_started = True
self.poll_timer = event.reactor.schedule(0.5, PollTimeout(self))

def run(self):
Container(self).run()

def on_accepted(self, event):
self.n_accepted += 1
if self.received == self.rx_limit and self.n_accepted == self.received and not self.poll_timer_started:
self.poll_timer_started = True
self.poll_timer = event.reactor.schedule(0.5, PollTimeout(self))

def on_released(self, event):
self.n_released += 1
if self.received == self.rx_limit and self.n_released == self.count and not self.poll_timer_started:
self.poll_timer_started = True
self.poll_timer = event.reactor.schedule(0.5, PollTimeout(self))

def verify_released(self, large_message=False):
"""
Verify the link released count by releasing all received messages
Expand Down

0 comments on commit 71e7c08

Please sign in to comment.