Several test reliability improvements

See commit messages.