Commit 5552def
authored
Fix and improve a flaky test (#3275)
## Summary
Fixed inconsistent test duration and occational `panic timeout` in
Test_PeerConnection_RTX_E2E
```
panic: timeout
goroutine 4309 [running]:
github.com/pion/webrtc/v4.Test_PeerConnection_RTX_E2E.TimeOut.func5()
/Users/ytakeda/go/pkg/mod/github.com/pion/transport/[email protected]/test/util.go:27 +0xb4
created by time.goFunc
/Users/ytakeda/sdk/go1.25.4/src/time/sleep.go:215 +0x44
```
### Problem
The test was timing out intermittently (0.2s-18.6s variance) when run
with the race detector due to:
* Random 20% packet loss causing unpredictable RTX detection timing
* Missing goroutine cleanup causing hangs
* Race detector overhead amplifying timing issues
```
go test -v -race -run Test_PeerConnection_RTX_E2E -count 20
=== RUN Test_PeerConnection_RTX_E2E
--- PASS: Test_PeerConnection_RTX_E2E (7.46s)
=== RUN Test_PeerConnection_RTX_E2E
--- PASS: Test_PeerConnection_RTX_E2E (1.42s)
=== RUN Test_PeerConnection_RTX_E2E
--- PASS: Test_PeerConnection_RTX_E2E (0.72s)
=== RUN Test_PeerConnection_RTX_E2E
--- PASS: Test_PeerConnection_RTX_E2E (18.62s)
=== RUN Test_PeerConnection_RTX_E2E
--- PASS: Test_PeerConnection_RTX_E2E (1.22s)
:
```
### Solution
1. Deterministic packet dropping - Changed from random 20% loss to dropping every 5th packet, ensuring predictable NACK/RTX triggering
2. Dynamic payload type detection - Uses negotiated payload type instead of hardcoded 96, making the test robust to codec configuration changes
3. Proper goroutine cleanup - Added context-based cleanup for RTCP reader and OnTrack callback
4. Fail-fast validation - Checks assertion return values and exits immediately on failure
5. Correct cleanup order - Closes peer connections before stopping the virtual network
### Result
* Consistent ~0.21s execution time (tested 50 runs with race detector)
* No more timeouts
* Still validates NACK/RTX behavior as intended by PR #2919
```
go test -v -race -run Test_PeerConnection_RTX_E2E -count 10
=== RUN Test_PeerConnection_RTX_E2E
--- PASS: Test_PeerConnection_RTX_E2E (0.21s)
=== RUN Test_PeerConnection_RTX_E2E
--- PASS: Test_PeerConnection_RTX_E2E (0.21s)
=== RUN Test_PeerConnection_RTX_E2E
--- PASS: Test_PeerConnection_RTX_E2E (0.21s)
=== RUN Test_PeerConnection_RTX_E2E
--- PASS: Test_PeerConnection_RTX_E2E (0.21s)
=== RUN Test_PeerConnection_RTX_E2E
--- PASS: Test_PeerConnection_RTX_E2E (0.21s)
=== RUN Test_PeerConnection_RTX_E2E
--- PASS: Test_PeerConnection_RTX_E2E (0.21s)
=== RUN Test_PeerConnection_RTX_E2E
--- PASS: Test_PeerConnection_RTX_E2E (0.21s)
=== RUN Test_PeerConnection_RTX_E2E
--- PASS: Test_PeerConnection_RTX_E2E (0.21s)
=== RUN Test_PeerConnection_RTX_E2E
--- PASS: Test_PeerConnection_RTX_E2E (0.21s)
=== RUN Test_PeerConnection_RTX_E2E
--- PASS: Test_PeerConnection_RTX_E2E (0.21s)
PASS
ok github.com/pion/webrtc/v4 3.373s
```1 parent 418e18c commit 5552def
1 file changed
+93
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
| |||
2353 | 2352 | | |
2354 | 2353 | | |
2355 | 2354 | | |
2356 | | - | |
2357 | | - | |
2358 | | - | |
2359 | | - | |
2360 | 2355 | | |
2361 | 2356 | | |
2362 | 2357 | | |
2363 | 2358 | | |
2364 | 2359 | | |
2365 | 2360 | | |
| 2361 | + | |
| 2362 | + | |
| 2363 | + | |
| 2364 | + | |
| 2365 | + | |
| 2366 | + | |
| 2367 | + | |
| 2368 | + | |
| 2369 | + | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
| 2374 | + | |
| 2375 | + | |
| 2376 | + | |
| 2377 | + | |
| 2378 | + | |
| 2379 | + | |
| 2380 | + | |
| 2381 | + | |
| 2382 | + | |
| 2383 | + | |
| 2384 | + | |
| 2385 | + | |
| 2386 | + | |
| 2387 | + | |
| 2388 | + | |
| 2389 | + | |
| 2390 | + | |
| 2391 | + | |
| 2392 | + | |
2366 | 2393 | | |
2367 | 2394 | | |
2368 | 2395 | | |
2369 | | - | |
| 2396 | + | |
| 2397 | + | |
2370 | 2398 | | |
| 2399 | + | |
| 2400 | + | |
| 2401 | + | |
| 2402 | + | |
2371 | 2403 | | |
2372 | 2404 | | |
2373 | 2405 | | |
| |||
2376 | 2408 | | |
2377 | 2409 | | |
2378 | 2410 | | |
| 2411 | + | |
| 2412 | + | |
| 2413 | + | |
| 2414 | + | |
| 2415 | + | |
| 2416 | + | |
2379 | 2417 | | |
2380 | 2418 | | |
| 2419 | + | |
| 2420 | + | |
| 2421 | + | |
| 2422 | + | |
| 2423 | + | |
| 2424 | + | |
2381 | 2425 | | |
2382 | | - | |
| 2426 | + | |
2383 | 2427 | | |
2384 | | - | |
2385 | | - | |
2386 | 2428 | | |
2387 | 2429 | | |
2388 | | - | |
2389 | | - | |
2390 | | - | |
| 2430 | + | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
| 2437 | + | |
| 2438 | + | |
| 2439 | + | |
2391 | 2440 | | |
| 2441 | + | |
2392 | 2442 | | |
2393 | 2443 | | |
2394 | 2444 | | |
2395 | 2445 | | |
2396 | | - | |
2397 | | - | |
| 2446 | + | |
| 2447 | + | |
| 2448 | + | |
| 2449 | + | |
| 2450 | + | |
| 2451 | + | |
| 2452 | + | |
| 2453 | + | |
| 2454 | + | |
| 2455 | + | |
| 2456 | + | |
2398 | 2457 | | |
2399 | | - | |
| 2458 | + | |
| 2459 | + | |
2400 | 2460 | | |
2401 | 2461 | | |
2402 | 2462 | | |
2403 | 2463 | | |
2404 | | - | |
| 2464 | + | |
| 2465 | + | |
| 2466 | + | |
| 2467 | + | |
2405 | 2468 | | |
2406 | 2469 | | |
| 2470 | + | |
| 2471 | + | |
| 2472 | + | |
2407 | 2473 | | |
2408 | 2474 | | |
2409 | | - | |
| 2475 | + | |
2410 | 2476 | | |
2411 | 2477 | | |
2412 | 2478 | | |
| 2479 | + | |
| 2480 | + | |
| 2481 | + | |
| 2482 | + | |
| 2483 | + | |
2413 | 2484 | | |
2414 | 2485 | | |
2415 | 2486 | | |
2416 | 2487 | | |
2417 | 2488 | | |
2418 | | - | |
| 2489 | + | |
| 2490 | + | |
| 2491 | + | |
| 2492 | + | |
2419 | 2493 | | |
| 2494 | + | |
2420 | 2495 | | |
0 commit comments