[minor] only emit data in the next loop, added test
[fix] do add tests