The test doesn't work currently because the log might be finalized before wait_for_debug_log is started, in which case it will assume the log is empty and fail to detect any line.
Fix this by calling wait_for_debug_log first. Fixes core#24060.
This concludes backport of core#24192
https://github.com/bitcoin/bitcoin/pull/24192/commits/fa7b07571f24b6def6effdd4cc1b96c7507bf959
Depends on D12620