Calculate context for tasks with dependencies

Also:
 - fixed the order tree is traversed in
 - fixed `evaluate_recursively` variable leak
 - added couple more tests for uncovered cases
 - fixed premature db session flush

I had to split convey_task_result's transaction into two to give some
room for concurrency. As far as I can tell, it should not affect the
process since all the crucial data will be reread once again in the
second transaction. Anyway, this is a temporary measure and when we
switch to MySQL, we should review it once again.

Closes-bug: #1339614
Change-Id: I9246931749f13df157d474cf75755462f7336bc7
Merge "Calculate context for tasks with dependencies"