Add getlasterror calls to prevent races in certain tests