Add tests for stale lock handling

Enough tests to make sure that all LUA scripts work.