Description
This issue is related to REEF-817. TreeTopology does not work correctly when the root task is added later than child tasks.
TreeTopology uses the prev field to track the lastly added leaf without considering that the root task might not be present yet. Thus if the root task is added later than others, TreeTopology.addTask sets prev as the root task before it exits, leading to incorrect sibling relations between nodes.
This bug can be reproduced by doing the following:
1. add two child tasks
2. add root task
3. add five child tasks
This was first found by chobrian.