refactored the test code and changed when each test run ends

Change-Id: I9ca7f6ed4b1f28e0dc26199d73106e6972dec7bd