Fix a potential bug that the lock might be created in wrong dir.

Separate the test code.