Treewatcher test and fix possible race condition