This was observed while running behat, on fast machines, multiple discussions are created at same seconds (Also possible on live server.). MDL-51285
It will be nice to fix forum_get_discussion_neighbours which can sort the neighbouring discussions created at same time.