From 146c727924674f1bf59a216b01d8ed5f534c287a Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <eelco.dolstra@logicblox.com>
Date: Wed, 30 Dec 2015 12:40:29 +0100
Subject: [PATCH] waitForUnit: Fail if the unit reaches inactive state with no
 pending jobs

This prevents waitForUnit for looping for many minutes before giving
up.
---
 nixos/lib/test-driver/Machine.pm | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/nixos/lib/test-driver/Machine.pm b/nixos/lib/test-driver/Machine.pm
index 41088ed75f7e..8ac0a31f2875 100644
--- a/nixos/lib/test-driver/Machine.pm
+++ b/nixos/lib/test-driver/Machine.pm
@@ -381,6 +381,11 @@ sub waitForUnit {
             my $info = $self->getUnitInfo($unit);
             my $state = $info->{ActiveState};
             die "unit ‘$unit’ reached state ‘$state’\n" if $state eq "failed";
+            if ($state eq "inactive") {
+                my ($status, $jobs) = $self->execute("systemctl list-jobs --full 2>&1");
+                die "unit ‘$unit’ is inactive and there are no pending jobs\n"
+                    if $jobs =~ /No jobs/; # FIXME: fragile
+            }
             return 1 if $state eq "active";
         };
     });