Fix exception when shutting down test stubs