From fdf7b1706c8571616c6af3c2fdc4f02c549e340d Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 7 Nov 2011 20:56:36 +0000 Subject: [PATCH] =?utf8?q?complete-run:=20Bugfix:=20Don=E2=80=99t=20call?= =?utf8?q?=20recv=20inside=20a=20callback=20when=20cleanly=20exiting=20i3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- testcases/complete-run.pl | 53 +++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/testcases/complete-run.pl b/testcases/complete-run.pl index e2d8ccb8..6cd00fe8 100755 --- a/testcases/complete-run.pl +++ b/testcases/complete-run.pl @@ -139,7 +139,9 @@ sub take_job { my $time_before_start = [gettimeofday]; my $pid; - if (!$dont_start) { + if ($dont_start) { + $activate_cv->send(1); + } else { $pid = activate_i3( unix_socket_path => "/tmp/nested-$display-activation", display => $display, @@ -161,20 +163,33 @@ sub take_job { # Don’t bother killing i3 when we haven’t started it return if $dont_start; + my $kill_cv = AnyEvent->condvar; + # When measuring code coverage, try to exit i3 cleanly (otherwise, .gcda # files are not written) and fallback to killing it - if ($coverage_testing) { + if ($coverage_testing || $valgrind) { my $exited = 0; - eval { - say "Exiting i3 cleanly..."; - i3("/tmp/nested-$display")->command('exit')->recv; - $exited = 1; - }; - return if $exited; + say "[$display] Exiting i3 cleanly..."; + my $i3 = i3("/tmp/nested-$display"); + $i3->connect->cb(sub { + if (!$_[0]->recv) { + # Could not connect to i3, just kill -9 it + kill(9, $pid) or die "Could not kill i3 using kill($pid)"; + $kill_cv->send(); + } else { + # Connected. Now send exit and continue once that’s acked. + $i3->command('exit')->cb(sub { + $kill_cv->send(); + }); + } + }); + } else { + # No coverage testing or valgrind? Just kill -9 i3. + kill(9, $pid) or die "Could not kill i3 using kill($pid)"; + $kill_cv->send(); } - say "[$display] killing i3"; - kill(9, $pid) or die "could not kill i3"; + return $kill_cv; }; # This will be called as soon as i3 is running and answered to our @@ -224,21 +239,21 @@ sub take_job { $aggregator->add($test, $parser); push @done, [ $test, $output ]; - $kill_i3->(); + my $exitcv = $kill_i3->(); + $exitcv->cb(sub { - undef $_ for @watchers; - if (@done == $num) { - $cv->send; - } else { - take_job($display); - } + undef $_ for @watchers; + if (@done == $num) { + $cv->send; + } else { + take_job($display); + } + }); } ); push @watchers, $w; } }); - - $activate_cv->send(1) if $dont_start; } $cv->recv; -- 2.39.5