tests: close databases to avoid errors on Windows

Fixes #655 and makes progress on #670.