From d142a29df8566b113a7639b22a8e956a3e7ab9d2 Mon Sep 17 00:00:00 2001
From: Kristoffer Richardsson <kristoffer@bitcraze.io>
Date: Wed, 12 Jun 2019 16:50:41 +0200
Subject: [PATCH] #119 Updates to restart system tests

---
 sys_test/swarm_test_rig/rig_support.py     | 20 ++++++++++----------
 sys_test/swarm_test_rig/test_connection.py | 13 ++++++++++++-
 2 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/sys_test/swarm_test_rig/rig_support.py b/sys_test/swarm_test_rig/rig_support.py
index f510ada..9fec7a7 100644
--- a/sys_test/swarm_test_rig/rig_support.py
+++ b/sys_test/swarm_test_rig/rig_support.py
@@ -43,7 +43,7 @@ class RigSupport:
         ]
 
     def restart_devices(self, uris):
-        def send_packets(uris, value):
+        def send_packets(uris, value, description):
             for uri in uris:
                 devid, channel, datarate, address = RadioDriver.parse_uri(uri)
                 radio.set_channel(channel)
@@ -52,17 +52,16 @@ class RigSupport:
 
                 received_packet = False
                 for i in range(10):
-                    # TODO krri Seems to work better with a pause here,
-                    #      investigate why
-                    time.sleep(0.2)
                     result = radio.send_packet((0xf3, 0xfe, value))
                     if result.ack is True:
                         received_packet = True
+                        # if i > 0:
+                        #     print('Lost packets', i, uri)
                         break
-                    time.sleep(0.1)
 
                 if not received_packet:
-                    raise Exception('Failed to restart device')
+                    raise Exception('Failed to turn device {}, for {}'.
+                                    format(description, uri))
 
         print('Restarting devices')
 
@@ -70,8 +69,9 @@ class RigSupport:
         BOOTLOADER_CMD_SYSON = 0x03
 
         radio = Crazyradio()
-        send_packets(uris, BOOTLOADER_CMD_SYSOFF)
-        time.sleep(0.1)
-        send_packets(uris, BOOTLOADER_CMD_SYSON)
+        send_packets(uris, BOOTLOADER_CMD_SYSOFF, 'off')
+        send_packets(uris, BOOTLOADER_CMD_SYSON, 'on')
+
+        # Wait for devices to boot
+        time.sleep(8)
         radio.close()
-        time.sleep(5)
diff --git a/sys_test/swarm_test_rig/test_connection.py b/sys_test/swarm_test_rig/test_connection.py
index 5348621..14c4b21 100644
--- a/sys_test/swarm_test_rig/test_connection.py
+++ b/sys_test/swarm_test_rig/test_connection.py
@@ -88,9 +88,20 @@ class TestConnection(unittest.TestCase):
 
     def test_that_all_devices_are_restarted(self):
         # Fixture
+        uris = self.test_rig_support.all_uris
+
         # Test
         # Assert
-        self.test_rig_support.restart_devices(self.test_rig_support.all_uris)
+        self.test_rig_support.restart_devices(uris)
+
+    def test_that_all_devices_are_restarted_multiple_times(self):
+        # Fixture
+        uris = self.test_rig_support.all_uris
+
+        # Test
+        # Assert
+        for i in range(10):
+            self.test_rig_support.restart_devices(uris)
 
     def test_that_the_same_cf_object_can_be_connected_multiple_times(self):
         # Fixture
-- 
GitLab