summaryrefslogtreecommitdiffstats
path: root/nixos/lib
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2016-05-24 16:33:14 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-05-24 16:33:14 +0200
commitad29b726866b5abeed9ad05cad52995295cf4813 (patch)
treed924f7242909f29f379e28c1c0de362dceb0338d /nixos/lib
parent5420f7f6e0e97df12842628462b6ae8495ff0bd6 (diff)
test-driver: Fix "unit X is inactive and there are no pending jobs"
This was causing many random test failures.
Diffstat (limited to 'nixos/lib')
-rw-r--r--nixos/lib/test-driver/Machine.pm12
1 files changed, 10 insertions, 2 deletions
diff --git a/nixos/lib/test-driver/Machine.pm b/nixos/lib/test-driver/Machine.pm
index 37d6518fd8d7..1a243918c22f 100644
--- a/nixos/lib/test-driver/Machine.pm
+++ b/nixos/lib/test-driver/Machine.pm
@@ -382,9 +382,17 @@ sub waitForUnit {
my $state = $info->{ActiveState};
die "unit ‘$unit’ reached state ‘$state’\n" if $state eq "failed";
if ($state eq "inactive") {
+ # If there are no pending jobs, then assume this unit
+ # will never reach active state.
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
+ if ($jobs =~ /No jobs/) { # FIXME: fragile
+ # Handle the case where the unit may have started
+ # between the previous getUnitInfo() and
+ # list-jobs.
+ my $info2 = $self->getUnitInfo($unit);
+ die "unit ‘$unit’ is inactive and there are no pending jobs\n"
+ if $info2->{ActiveState} eq $state;
+ }
}
return 1 if $state eq "active";
};