Commit a24b7b3
authored
test(appsec): make server startup failures diagnosable and port reuse safe (#19674)
APPSEC-69623
All 13 quarantined tests here fail in `appsec_application_server`, not in their own bodies. The recorded error is the "Server failed to start" assertion, and the runs with a duration cluster at 22.0–22.6s against a ~13s startup budget.
**The failures are undebuggable.** The assertion interpolated `getattr(server_process, "stdout", None)` — `None` for a `multiprocessing.Process`, a stream rather than text for a `Popen` — so every one reports a literal `None`. It now reports what is *not* already in the captured output: exit code (`None` = too slow, non-zero = died), whether the port is still taken, and the command.
**Port 8050 is shared by 31 tests**, these suites run serially, and teardown is best effort (SIGTERM to the process group, `join(timeout=5)`, each step in `except/pass`). A gunicorn worker outliving that leaves the port taken and the next test can't bind. Now waits for the port both before starting and after tearing down.
**The suites never ran.** The first push was green with zero test events for any of the 13 tests: `tests/appsec/appsec_utils.py` matched 15 suites but none of the `appsec_integrations_*` ones that import it, because `@appsec` covers `ddtrace/appsec/*` source only and each suite lists just its own test directory. The second commit adds the file to the six suites whose tests import it (grep-verified: `flask_tests` 7 files, `fastapi_tests` 2, `django_tests` 1, plus `iast_packages` and `iast_tdd_propagation`). It now matches 21 suites; `suitespec-check` passes both gates.
Notes:
- The port wait tests whether the port can be **bound**, not whether it accepts connections. `connect()` reports a port free once a bound server's listen backlog fills — exactly the wedged state worth catching — and opens real connections to a live server. My first version did use `connect()` and wrongly reported "released" after 0.3s against a still-bound socket.
- Warns rather than raises when the port never frees; raising in teardown would turn one leak into a failure across every appsec server suite.
- No per-worker port offsets: these suites have no `-n` in the riotfile, so the collision is sequential, not concurrent.
- The newly triggered suites also hold quarantined tests this branch does not fix — the SCA reachability pair (fixed in #19671) and `test_django_insecure_cookie_secure` (an `index_aspect` bug). Deliberately left unkeyed rather than un-quarantined on a commit that would not fix them.
Blast radius: `appsec_application_server` backs all five server context managers, and the suitespec change widens what CI runs on such edits — both intended.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: christophe.papazian <christophe.papazian@datadoghq.com>1 parent 37d2e79 commit a24b7b3
2 files changed
Lines changed: 63 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
25 | 69 | | |
26 | 70 | | |
27 | 71 | | |
| |||
335 | 379 | | |
336 | 380 | | |
337 | 381 | | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
338 | 386 | | |
339 | 387 | | |
340 | 388 | | |
| |||
374 | 422 | | |
375 | 423 | | |
376 | 424 | | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
| 425 | + | |
| 426 | + | |
381 | 427 | | |
382 | 428 | | |
383 | 429 | | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
| 430 | + | |
| 431 | + | |
388 | 432 | | |
389 | 433 | | |
390 | 434 | | |
| |||
399 | 443 | | |
400 | 444 | | |
401 | 445 | | |
402 | | - | |
403 | | - | |
404 | | - | |
| 446 | + | |
| 447 | + | |
405 | 448 | | |
406 | 449 | | |
407 | 450 | | |
| |||
433 | 476 | | |
434 | 477 | | |
435 | 478 | | |
436 | | - | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
437 | 482 | | |
438 | 483 | | |
439 | 484 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
| |||
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| 88 | + | |
87 | 89 | | |
88 | 90 | | |
89 | 91 | | |
| |||
148 | 150 | | |
149 | 151 | | |
150 | 152 | | |
| 153 | + | |
151 | 154 | | |
152 | 155 | | |
153 | 156 | | |
| |||
162 | 165 | | |
163 | 166 | | |
164 | 167 | | |
| 168 | + | |
165 | 169 | | |
166 | 170 | | |
167 | 171 | | |
| |||
176 | 180 | | |
177 | 181 | | |
178 | 182 | | |
| 183 | + | |
179 | 184 | | |
180 | 185 | | |
181 | 186 | | |
| |||
190 | 195 | | |
191 | 196 | | |
192 | 197 | | |
| 198 | + | |
193 | 199 | | |
194 | 200 | | |
195 | 201 | | |
| |||
0 commit comments