Fix raft

I added a test for the fix. 
/cc @unihorn @soheilhy