Interrupt a subprocess after a second.
(self, command)
| 157 | self.assertEqual(status, 0) |
| 158 | |
| 159 | def assert_interrupts(self, command): |
| 160 | """ |
| 161 | Interrupt a subprocess after a second. |
| 162 | """ |
| 163 | if threading.main_thread() != threading.current_thread(): |
| 164 | raise pytest.skip("Can't run this test if not in main thread.") |
| 165 | |
| 166 | # Some tests can overwrite SIGINT handler (by using pdb for example), |
| 167 | # which then breaks this test, so just make sure it's operating |
| 168 | # normally. |
| 169 | signal.signal(signal.SIGINT, signal.default_int_handler) |
| 170 | |
| 171 | def interrupt(): |
| 172 | # Wait for subprocess to start: |
| 173 | time.sleep(0.5) |
| 174 | interrupt_main() |
| 175 | |
| 176 | threading.Thread(target=interrupt).start() |
| 177 | start = time.time() |
| 178 | try: |
| 179 | result = command() |
| 180 | except KeyboardInterrupt: |
| 181 | # Success! |
| 182 | pass |
| 183 | end = time.time() |
| 184 | self.assertTrue( |
| 185 | end - start < 2, "Process didn't die quickly: %s" % (end - start) |
| 186 | ) |
| 187 | return result |
| 188 | |
| 189 | def test_system_interrupt(self): |
| 190 | """ |
no test coverage detected