Fix ENG-5310 and add tests.

Race condition when last batch has failures. batch failure callback not called and failure processing end-of-processing is put before batch lines for single processing. Added tests.