Fix deadlock and update tests

test for:
- the deadlock repaired in this commit
- normal deadlock (circular dependencies should be detected)
- redo-exec
- update 201-fail: make sure that after a failure, next target is not built
  (another thing fixed in this commit, same problem as the deadlock)