Example #1
0
    def test_that_connection_time_scales_with_more_devices_with_cache(self):
        # Fixture
        self.test_rig_support.restart_devices(self.test_rig_support.all_uris)

        # Fill caches first by connecting to all devices
        factory = CachededFactory(rw_cache='./cache')
        with Swarm(self.test_rig_support.all_uris, factory=factory):
            pass

        EXPECTED_CONNECTION_TIME = 1.5

        for nr_of_devices in range(1, len(self.test_rig_support.all_uris)):
            # Test
            uris = self.test_rig_support.all_uris[:nr_of_devices]

            start_time = time.time()
            with Swarm(uris, factory=factory):
                connected_time = time.time()

            actual = connected_time - start_time
            max_expected = EXPECTED_CONNECTION_TIME * nr_of_devices
            print('Connection time for', nr_of_devices, ':', actual,
                  ', per device:', actual / nr_of_devices)

            # Assert
            self.assertLess(actual, max_expected)
Example #2
0
    def test_memory_mapping_with_all_eds(self):
        # Fixture
        uris = self.test_rig_support.all_uris
        self.test_rig_support.restart_devices(uris)
        factory = CachededFactory(rw_cache='./cache')

        # Test and Assert
        with Swarm(uris, factory=factory) as swarm:
            swarm.parallel_safe(self.assert_memory_mapping)
    def test_that_requested_logging_is_received_properly_from_all_eds(self):
        # Fixture
        uris = self.test_rig_support.all_uris
        self.test_rig_support.restart_devices(uris)
        factory = CachededFactory(rw_cache='./cache')

        # Test and Assert
        with Swarm(uris, factory=factory) as swarm:
            swarm.parallel_safe(self.assert_add_logging_and_get_non_zero_value)
    def test_open_with_context_management(self):
        # Fixture

        # Test
        with Swarm(self.uris, factory=self.factory):
            pass

        # Assert
        for uri, mock in self.factory.mocks.items():
            mock.open_link.assert_called_once_with()
            mock.close_link.assert_called_once_with()
Example #5
0
    def test_that_connection_time_scales_with_more_devices_without_cache(self):
        # Fixture
        self.test_rig_support.restart_devices(self.test_rig_support.all_uris)

        EXPECTED_CONNECTION_TIME = 5

        for nr_of_devices in range(1, len(self.test_rig_support.all_uris)):
            # Test
            uris = self.test_rig_support.all_uris[:nr_of_devices]

            start_time = time.time()
            with Swarm(uris):
                connected_time = time.time()

            actual = connected_time - start_time
            max_expected = EXPECTED_CONNECTION_TIME * nr_of_devices
            print('Connection time for', nr_of_devices, ':', actual,
                  ', per device:', actual / nr_of_devices)

            # Assert
            self.assertLess(actual, max_expected)
    for _ in range(2):
        # The time for one revolution
        circle_time = 8

        steps = circle_time * fs
        for _ in range(steps):
            ed.commander.send_hover_setpoint(d * comp * math.pi / circle_time,
                                             0, 360.0 / circle_time, z)
            time.sleep(fsi)

    poshold(ed, 2, z)

    for r in range(ramp):
        ed.commander.send_hover_setpoint(0, 0, 0,
                                         base + (ramp - r) * (z - base) / ramp)
        time.sleep(fsi)

    poshold(ed, 1, base)

    ed.commander.send_stop_setpoint()


if __name__ == '__main__':
    edlib.crtp.init_drivers(enable_debug_driver=False)

    factory = CachededFactory(rw_cache='./cache')
    with Swarm(uris, factory=factory) as swarm:
        swarm.parallel(reset_estimator)
        swarm.parallel(run_sequence, args_dict=params)
    def setUp(self):
        self.uris = [self.URI1, self.URI2, self.URI3]
        self.factory = MockFactory()

        self.sut = Swarm(self.uris, factory=self.factory)
class TestSwarm(unittest.TestCase):
    URI1 = 'uri1'
    URI2 = 'uri2'
    URI3 = 'uri3'

    def setUp(self):
        self.uris = [self.URI1, self.URI2, self.URI3]
        self.factory = MockFactory()

        self.sut = Swarm(self.uris, factory=self.factory)

    def test_that_instances_are_created(self):
        # Fixture

        # Test

        # Assert
        actual = len(self.factory.mocks)
        expected = len(self.uris)
        self.assertEqual(expected, actual)

    def test_that_all_links_are_opened(self):
        # Fixture

        # Test
        self.sut.open_links()

        # Assert
        for uri, mock in self.factory.mocks.items():
            mock.open_link.assert_called_once_with()

    def test_open_of_already_opened_swarm_raises_exception(self):
        # Fixture
        self.sut.open_links()

        # Test
        # Assert
        with self.assertRaises(Exception):
            self.sut.open_links()

    def test_failed_open_of_one_link_closes_all_and_raises_exception(self):
        # Fixture
        self.factory.mocks[self.URI2].open_link.side_effect = Exception()

        # Test
        # Assert
        with self.assertRaises(Exception):
            self.sut.open_links()

        for uri, mock in self.factory.mocks.items():
            mock.close_link.assert_called_once_with()

    def test_that_all_links_are_closed(self):
        # Fixture
        self.sut.open_links()

        # Test
        self.sut.close_links()

        # Assert
        for uri, mock in self.factory.mocks.items():
            mock.close_link.assert_called_once_with()

    def test_open_with_context_management(self):
        # Fixture

        # Test
        with Swarm(self.uris, factory=self.factory):
            pass

        # Assert
        for uri, mock in self.factory.mocks.items():
            mock.open_link.assert_called_once_with()
            mock.close_link.assert_called_once_with()

    def test_sequential_execution_without_arguments(self):
        # Fixture
        func = MagicMock()

        # Test
        self.sut.sequential(func)

        # Assert
        for uri, mock in self.factory.mocks.items():
            func.assert_any_call(mock)

    def test_sequential_execution(self):
        # Fixture
        func = MagicMock()
        args_dict = {
            self.URI1: ['ed1-arg1'],
            self.URI2: ['ed2-arg1'],
            self.URI3: ['ed3-arg1'],
        }

        ed1 = self.factory.mocks[self.URI1]
        ed2 = self.factory.mocks[self.URI2]
        ed3 = self.factory.mocks[self.URI3]

        # Test
        self.sut.sequential(func, args_dict=args_dict)

        # Assert
        func.assert_any_call(ed1, 'ed1-arg1')
        func.assert_any_call(ed2, 'ed2-arg1')
        func.assert_any_call(ed3, 'ed3-arg1')

    def test_parallel_execution_without_arguments(self):
        # Fixture
        func = MagicMock()

        # Test
        self.sut.parallel(func)

        # Assert
        for uri, mock in self.factory.mocks.items():
            func.assert_any_call(mock)

    def test_parallel_execution(self):
        # Fixture
        func = MagicMock()
        args_dict = {
            self.URI1: ['ed1-arg1'],
            self.URI2: ['ed2-arg1'],
            self.URI3: ['ed3-arg1'],
        }

        ed1 = self.factory.mocks[self.URI1]
        ed2 = self.factory.mocks[self.URI2]
        ed3 = self.factory.mocks[self.URI3]

        # Test
        self.sut.parallel(func, args_dict=args_dict)

        # Assert
        func.assert_any_call(ed1, 'ed1-arg1')
        func.assert_any_call(ed2, 'ed2-arg1')
        func.assert_any_call(ed3, 'ed3-arg1')

    def test_parallel_execution_with_exception(self):
        # Fixture
        func_fail = MagicMock()
        func_fail.side_effect = Exception()
        args_dict = {
            self.URI1: ['ed1-arg1'],
            self.URI2: ['ed2-arg1'],
            self.URI3: ['ed3-arg1'],
        }

        ed1 = self.factory.mocks[self.URI1]
        ed2 = self.factory.mocks[self.URI2]
        ed3 = self.factory.mocks[self.URI3]

        # Test
        self.sut.parallel(func_fail, args_dict=args_dict)

        # Assert
        func_fail.assert_any_call(ed1, 'ed1-arg1')
        func_fail.assert_any_call(ed2, 'ed2-arg1')
        func_fail.assert_any_call(ed3, 'ed3-arg1')

    def test_parallel_safe_execution_with_exception(self):
        # Fixture
        func_fail = MagicMock()
        func_fail.side_effect = Exception()
        args_dict = {
            self.URI1: ['ed1-arg1'],
            self.URI2: ['ed2-arg1'],
            self.URI3: ['ed3-arg1'],
        }

        # Test
        # Assert
        with self.assertRaises(Exception):
            self.sut.parallel_safe(func_fail, args_dict=args_dict)