Fixes the issue mentioned here: #7622 (comment)
This test was too sensitive to how many transactions might get selected; this change makes it more robust, and if there’s a failure due to future changes, the test is now somewhat better structured and commented to make fixing easier.