Fixed bugs in the previous send callback fix and added new test cases

I fixed issues in the previous fix.

The call order of flush() and the callback part in setupSendCallback() matters in the original design and the previous approach actually can't work perfectly in both order. So I added a new array to handle that.

I also added 2 test cases for this.