Add testing infrastructure.
Made advisory_lock actually release the lock on exit (!)
Close cursor on normal exit

This isn't perfect but it minimizes resource leaks in the common case