For ENG-6530, refactor code to avoid redundancy. Discard empty buffers
after moving tail to new buffer. Modify testcase to adapt the new logic.