backport improved test function from 4.3