Fix deadlock in tests