|
17 | 17 | class TestSubscribeObjectModel(unittest.TestCase): |
18 | 18 | """Test suite for the object model subscription example.""" |
19 | 19 |
|
| 20 | + @staticmethod |
| 21 | + def _wait_for_data_available(subscribe_connection: SubscribeConnection, timeout: float = 1.0) -> bool: |
| 22 | + deadline = time.time() + timeout |
| 23 | + while time.time() < deadline: |
| 24 | + if subscribe_connection.has_data_available(): |
| 25 | + return True |
| 26 | + time.sleep(0.01) |
| 27 | + return False |
| 28 | + |
20 | 29 | def setUp(self): |
21 | 30 | """Set up test environment before each test.""" |
22 | 31 | self.tmp_dir = tempfile.TemporaryDirectory() |
@@ -131,6 +140,32 @@ def test_subscribe_object_model(self): |
131 | 140 | # Verify the test completed successfully |
132 | 141 | self.assertTrue(self.dcs_passed.is_set(), "The mock DCS did not complete successfully") |
133 | 142 |
|
| 143 | + def test_has_data_available_during_subscription_flow(self): |
| 144 | + """Test that has_data_available reflects queued model and patch updates.""" |
| 145 | + subscribe_connection = SubscribeConnection(SubscriptionMode.PATCH) |
| 146 | + subscribe_connection.connect(self.mock_dcs_socket_file) |
| 147 | + |
| 148 | + self.assertTrue( |
| 149 | + self._wait_for_data_available(subscribe_connection), |
| 150 | + "Expected the initial object model to be readable", |
| 151 | + ) |
| 152 | + |
| 153 | + subscribe_connection.get_object_model() |
| 154 | + |
| 155 | + self.assertTrue( |
| 156 | + self._wait_for_data_available(subscribe_connection), |
| 157 | + "Expected the next object model patch to be readable after acknowledge", |
| 158 | + ) |
| 159 | + |
| 160 | + subscribe_connection.get_object_model_patch() |
| 161 | + |
| 162 | + self.assertFalse(subscribe_connection.has_data_available()) |
| 163 | + |
| 164 | + subscribe_connection.close() |
| 165 | + |
| 166 | + self.server_thread.join(timeout=5) |
| 167 | + self.assertTrue(self.dcs_passed.is_set(), "The mock DCS did not complete successfully") |
| 168 | + |
134 | 169 |
|
135 | 170 | if __name__ == "__main__": |
136 | 171 | unittest.main() |
0 commit comments