瀏覽代碼

enhance terminal test (main process)

Bastien Sevajol 6 年之前
父節點
當前提交
cda184bc95
共有 1 個文件被更改,包括 15 次插入3 次删除
  1. 15 3
      tests/test_terminals.py

+ 15 - 3
tests/test_terminals.py 查看文件

@@ -1,6 +1,7 @@
1 1
 # coding: utf-8
2 2
 import time
3 3
 
4
+import os
4 5
 import pytest
5 6
 
6 7
 from synergine2.config import Config
@@ -176,17 +177,25 @@ class TestTerminals(BaseTest):
176 177
             simulation=simulation,
177 178
         )
178 179
 
180
+        terminal_pid = 0
181
+        core_pid = 0
182
+        global terminal_pid
183
+        global core_pid
184
+
179 185
         class MyMainTerminal(Terminal):
180 186
             main_process = True
181 187
 
182
-        terminal = MyMainTerminal(config, logger)
188
+            def run(self):
189
+                global terminal_pid
190
+                terminal_pid = os.getpid()
183 191
 
184
-        class Terminated(Exception):
185
-            pass
192
+        terminal = MyMainTerminal(config, logger)
186 193
 
187 194
         class MyCore(Core):
188 195
             def _end_cycle(self):
189 196
                 self._continue = False
197
+                global core_pid
198
+                core_pid = os.getpid()
190 199
 
191 200
         core = MyCore(
192 201
             config=config,
@@ -201,3 +210,6 @@ class TestTerminals(BaseTest):
201 210
         )
202 211
         core.run()
203 212
         core.cycle_manager.process_manager.terminate()
213
+
214
+        assert terminal_pid == os.getpid()
215
+        assert core_pid == 0  # because changed in other process