From 114716d91adf72189a1e3d80d848890dfbbf181f Mon Sep 17 00:00:00 2001
From: SKAJohanVenter <aventer@ska.ac.za>
Date: Fri, 8 Oct 2021 16:32:22 +0200
Subject: [PATCH] SAR-276 Cleaned up tests

---
 tests/{ => long_running_tasks}/reference_base_device.py    | 0
 .../{ => long_running_tasks}/test_reference_base_device.py | 2 +-
 tests/{ => long_running_tasks}/test_task_queue_manager.py  | 7 +++++--
 3 files changed, 6 insertions(+), 3 deletions(-)
 rename tests/{ => long_running_tasks}/reference_base_device.py (100%)
 rename tests/{ => long_running_tasks}/test_reference_base_device.py (99%)
 rename tests/{ => long_running_tasks}/test_task_queue_manager.py (98%)

diff --git a/tests/reference_base_device.py b/tests/long_running_tasks/reference_base_device.py
similarity index 100%
rename from tests/reference_base_device.py
rename to tests/long_running_tasks/reference_base_device.py
diff --git a/tests/test_reference_base_device.py b/tests/long_running_tasks/test_reference_base_device.py
similarity index 99%
rename from tests/test_reference_base_device.py
rename to tests/long_running_tasks/test_reference_base_device.py
index 27b56cfe..b9da1ccc 100644
--- a/tests/test_reference_base_device.py
+++ b/tests/long_running_tasks/test_reference_base_device.py
@@ -9,7 +9,7 @@ from unittest import mock
 from tango import EventType
 from tango.test_context import DeviceTestContext
 from tango.utils import EventCallback
-from .reference_base_device import (
+from reference_base_device import (
     BlockingBaseDevice,
     AsyncBaseDevice,
 )
diff --git a/tests/test_task_queue_manager.py b/tests/long_running_tasks/test_task_queue_manager.py
similarity index 98%
rename from tests/test_task_queue_manager.py
rename to tests/long_running_tasks/test_task_queue_manager.py
index f3fa032b..1d4d8790 100644
--- a/tests/test_task_queue_manager.py
+++ b/tests/long_running_tasks/test_task_queue_manager.py
@@ -222,8 +222,9 @@ class TestQueueManagerTasks:
 
             results = [i[0][0].result_code for i in my_cb.call_args_list]
             # 9/10 should be rejected since the first is busy and the queue length is 1
+            # Give a buffer of 2 just in case a task finishes up quicker than expected
             assert results[-1] == ResultCode.OK
-            for res in results[:-1]:
+            for res in results[:-3]:
                 assert res == ResultCode.REJECTED
 
         with patch.object(QueueManager, "result_callback") as my_cb:
@@ -235,9 +236,10 @@ class TestQueueManagerTasks:
                 time.sleep(0.5)
             results = [i[0][0].result_code for i in my_cb.call_args_list]
             # 8/10 should be rejected since two are taken to be processed.
+            # Give a buffer of 2 just in case a task finishes up quicker than expected
             assert results[-1] == ResultCode.OK
             assert results[-2] == ResultCode.OK
-            for res in results[:-2]:
+            for res in results[:-4]:
                 assert res == ResultCode.REJECTED
 
     @pytest.mark.timeout(5)
@@ -410,6 +412,7 @@ class TestQueueManagerExit:
             tr = TaskResult.from_task_result(qm.task_result)
             if tr.unique_id == unique_id and tr.result_code == ResultCode.ABORTED:
                 break
+            time.sleep(0.1)
 
         # Resume the commands
         qm.resume_tasks()
-- 
GitLab