The sorting algo differs in the test from the node algo if the number of accepted contenders is > AVALANCHE_CONTENDER_MAX_POLLABLE, which is a rare event.
To reproduce you can reduce AVALANCHE_CONTENDER_MAX_POLLABLE to some small number (4 is a good value) and run the test in a loop, it should fail quickly without this patch.