Following issue #14343, in (the still open) PR #16878 I used a specific approach to address the non-deterministic coverage issue and I'd like to present it here in general form to a wider audience to get additional opinions on that approach because I think it can be used on other such tests to mitigate non-determinism.
The approach can be broadly described by a 'recipe' for any given test:
- Run the coverage measuring script
contrib/devtools/test_deterministic_coverage.shmany times on the test and write down all branches that sometimes run and sometimes don't. - Figure out how to cause all of those branches to run from the test body.
- Add code at the end of the test (after all the assertions) that would cause all of those branches to run.
This approach worked effectively on the test DoS_mapOrphans in PR #16878 and I believe it can be used on some or maybe all of the tests listed in contrib/devtools/test_deterministic_coverage.sh.
As far as I can see, the only disadvantage for this approach is the seemingly unrelated code at the end of such tests required to ensure coverage but I believe any confusion can be eliminated by a comment explaining what it's there for.
What do people think?