Fix NNFI bug with two failing changes at head

If A is the head in A <- B <- C, and B failed, then C would be
correctly reparented to A.  Then if A failed, B and C would be
restarted, but C would not be reparented back to B.  This is
because the check around moving a change short-circuited if
there was no change ahead (which is the case if C is behind A
and A reports).

The solution to this is to still perform the move check even if
there is no change currently ahead (so that if there is a NNFI
change ahead, the current change will be moved behind it).  This
effectively means we should remove the "not item ahead" part of
the conditional around the move.

This part of the conditional serves two additional purposes --
to make sure that we don't dereference an attribute on item_ahead
if it is None, and also to ensure that the NNFI algorithm is not
applied to independent queues.

So the fix moves that part of the conditional out so that we can
safely reference the needed attributes if there is a change ahead,
and also makes explicit that we ignore the situation if we are
working on an independent change queue.

This also adds a test that failed (at the indicated position) with
the previous code.

Change-Id: I4cf5e868af7cddb7e95ef378abb966613ac9701c
2 files changed