Use listen callback to fix race in test