Browse Source

enhance terminal test (main process)

Bastien Sevajol 7 years ago
parent
commit
cda184bc95
1 changed files with 15 additions and 3 deletions
  1. 15 3
      tests/test_terminals.py

+ 15 - 3
tests/test_terminals.py View File

1
 # coding: utf-8
1
 # coding: utf-8
2
 import time
2
 import time
3
 
3
 
4
+import os
4
 import pytest
5
 import pytest
5
 
6
 
6
 from synergine2.config import Config
7
 from synergine2.config import Config
176
             simulation=simulation,
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
         class MyMainTerminal(Terminal):
185
         class MyMainTerminal(Terminal):
180
             main_process = True
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
         class MyCore(Core):
194
         class MyCore(Core):
188
             def _end_cycle(self):
195
             def _end_cycle(self):
189
                 self._continue = False
196
                 self._continue = False
197
+                global core_pid
198
+                core_pid = os.getpid()
190
 
199
 
191
         core = MyCore(
200
         core = MyCore(
192
             config=config,
201
             config=config,
201
         )
210
         )
202
         core.run()
211
         core.run()
203
         core.cycle_manager.process_manager.terminate()
212
         core.cycle_manager.process_manager.terminate()
213
+
214
+        assert terminal_pid == os.getpid()
215
+        assert core_pid == 0  # because changed in other process