Optimize retry_test code