history: Fix possible deadlock
history is a singleton object. It's created and finalized only once in an application's lifetime. But in tests, the same object may be reused after closing database, which can result in races that lock the GTask to never complete. So let's clear the thread variable when leaving the thread.
Edited by Mohammed Sadiq