Fix failing test cases
Changes according to comments
Rename variables to avoid confusion
Merge pull request #3292 from Randy-Ma/fix_failing_test_cases

Fix failing test cases because some entities are still in use after disposed