db: wrap test thread_in_query in ()