Commit 7c0b3e5
committed
fix(test): make test_schedstat_fd_closed_on_thread_exit not flaky
The previous assertion checked fcntl(fd, F_GETFD) != -1 after the
spawned thread exited. Linux readily recycles fd numbers, and other
tests in the same suite open many files concurrently (including their
own per-thread schedstat fds via tokio worker poll callbacks). When a
sibling test opened a file in the small window after our spawned thread
closed its schedstat fd, the fd number got reused and the check
incorrectly reported a leak.
Capture the path the fd points to via /proc/self/fd/<fd> inside the
spawned thread, and after join verify that the fd is either closed or
now points at a different file. Each thread opens schedstat for its own
tid, so /proc/self/task/<spawned_tid>/schedstat is unique to the
spawned thread's open and no concurrent test can collide on it.
Verified by running the full cargo test -p dial9-tokio-telemetry --lib
suite 13 times in a row with zero failures (previously failed roughly
3/10 runs), and confirmed the new test still catches a real leak by
temporarily mem::forget'ing the OwnedFd in the production path.1 parent 5433e82 commit 7c0b3e5
1 file changed
Lines changed: 39 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
609 | 609 | | |
610 | 610 | | |
611 | 611 | | |
612 | | - | |
613 | | - | |
614 | | - | |
615 | | - | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
616 | 628 | | |
617 | 629 | | |
618 | | - | |
619 | | - | |
620 | | - | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
621 | 637 | | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
622 | 641 | | |
623 | | - | |
624 | | - | |
| 642 | + | |
| 643 | + | |
625 | 644 | | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
626 | 656 | | |
627 | 657 | | |
0 commit comments