Fix buggy tests

This fixes a couple of tests that were failing in release mode. It needs to be backported to maintenance/1.8.x before release.