Skip to content

Commit

Permalink
Merge pull request #110 from openshift-kni/trex-app-timeout
Browse files Browse the repository at this point in the history
Stop trex-app after duration time is reached
  • Loading branch information
tkrishtop authored Dec 30, 2024
2 parents ef3f0eb + 188d111 commit 6d2fe0e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions trex-container-app/app/pyfiles/trexstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ def completed_stats(stats, warnings, port_a, port_b, profile, rate, duration):
packets = stats[port_a]["opackets"] + stats[port_b]["opackets"]
total_lost = lost * 100.0 / packets

log.info(f"\nPackets lost from {port_a} to {port_b}: {lost_a} packets, which is {percentage_lost_a}% packet loss")
log.info(f"Packets lost from {port_b} to {port_a}: {lost_b} packets, which is {percentage_lost_b}% packet loss")
log.info(f"Total packets lost: {lost} packets, which is {total_lost}% packet loss")
log.info(f"\nPackets lost from {port_a} to {port_b}: {lost_a} packets, which is {format(percentage_lost_a, '.10f')}% packet loss")
log.info(f"Packets lost from {port_b} to {port_a}: {lost_b} packets, which is {format(percentage_lost_b, '.10f')}% packet loss")
log.info(f"Total packets lost: {lost} packets, which is {format(total_lost, '.10f')}% packet loss")

if warnings:
log.info("\n\n*** test had warnings ****\n\n")
Expand Down
12 changes: 10 additions & 2 deletions trex-container-app/app/scripts/run-trex
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,16 @@ class STLS1(object):
# start monitory thread to post stats
self.start_stats_monitor()

# block until done
self.client.wait_on_traffic(ports=self.ports)
# block until done, having a timeout that expires after reaching the specified duration (if provided)
# with 1 second delay waiying after last packet is sent
if self.duration != -1:
try:
self.client.wait_on_traffic(ports=self.ports, timeout=self.duration, rx_delay_ms=1000)
except TRexTimeoutError as e:
log.info("Reached timeout, job will finish")
log.info(e)
else:
self.client.wait_on_traffic(ports=self.ports)

trexstats.force_exit = True

Expand Down

0 comments on commit 6d2fe0e

Please sign in to comment.