Improve test failure check
Partially revert 3019283237a35625f8a5e904b3053307309e7682