This test uses dependent signal handlers.
(self)
| 1267 | @unittest.skipUnless(hasattr(signal, "setitimer"), |
| 1268 | "test needs setitimer()") |
| 1269 | def test_stress_delivery_dependent(self): |
| 1270 | """ |
| 1271 | This test uses dependent signal handlers. |
| 1272 | """ |
| 1273 | N = self.decide_itimer_count() |
| 1274 | sigs = [] |
| 1275 | |
| 1276 | def first_handler(signum, frame): |
| 1277 | # 1e-6 is the minimum non-zero value for `setitimer()`. |
| 1278 | # Choose a random delay so as to improve chances of |
| 1279 | # triggering a race condition. Ideally the signal is received |
| 1280 | # when inside critical signal-handling routines such as |
| 1281 | # Py_MakePendingCalls(). |
| 1282 | signal.setitimer(signal.ITIMER_REAL, 1e-6 + random.random() * 1e-5) |
| 1283 | |
| 1284 | def second_handler(signum=None, frame=None): |
| 1285 | sigs.append(signum) |
| 1286 | |
| 1287 | # Here on Linux, SIGPROF > SIGALRM > SIGUSR1. By using both |
| 1288 | # ascending and descending sequences (SIGUSR1 then SIGALRM, |
| 1289 | # SIGPROF then SIGALRM), we maximize chances of hitting a bug. |
| 1290 | self.setsig(signal.SIGPROF, first_handler) |
| 1291 | self.setsig(signal.SIGUSR1, first_handler) |
| 1292 | self.setsig(signal.SIGALRM, second_handler) # for ITIMER_REAL |
| 1293 | |
| 1294 | expected_sigs = 0 |
| 1295 | deadline = time.monotonic() + support.SHORT_TIMEOUT |
| 1296 | |
| 1297 | while expected_sigs < N: |
| 1298 | os.kill(os.getpid(), signal.SIGPROF) |
| 1299 | expected_sigs += 1 |
| 1300 | # Wait for handlers to run to avoid signal coalescing |
| 1301 | while len(sigs) < expected_sigs and time.monotonic() < deadline: |
| 1302 | time.sleep(1e-5) |
| 1303 | |
| 1304 | os.kill(os.getpid(), signal.SIGUSR1) |
| 1305 | expected_sigs += 1 |
| 1306 | while len(sigs) < expected_sigs and time.monotonic() < deadline: |
| 1307 | time.sleep(1e-5) |
| 1308 | |
| 1309 | # All ITIMER_REAL signals should have been delivered to the |
| 1310 | # Python handler |
| 1311 | self.assertEqual(len(sigs), N, "Some signals were lost") |
| 1312 | |
| 1313 | @unittest.skipUnless(hasattr(signal, "setitimer"), |
| 1314 | "test needs setitimer()") |
nothing calls this directly
no test coverage detected