test_retrieval: fix shutdown logic to stop intermittent test failure