Implement the tick event

This makes our tests less flaky, shorter, and more readable.

fixes #2988
This commit is contained in:
Michael Stapelberg
2017-09-24 15:40:30 +02:00
parent 14c8cf8622
commit ce21de8dde
29 changed files with 457 additions and 734 deletions

View File

@ -16,46 +16,15 @@
use i3test;
SKIP: {
skip "AnyEvent::I3 too old (need >= 0.15)", 1 if $AnyEvent::I3::VERSION < 0.15;
my $i3 = i3(get_socket_path());
$i3->connect()->recv;
################################
# Window event
################################
# Events
my $new = AnyEvent->condvar;
my $focus = AnyEvent->condvar;
$i3->subscribe({
window => sub {
my ($event) = @_;
if ($event->{change} eq 'new') {
$new->send($event);
} elsif ($event->{change} eq 'focus') {
$focus->send($event);
}
}
})->recv;
open_window;
my @events = events_for(
sub { open_window },
'window');
my $t;
$t = AnyEvent->timer(
after => 0.5,
cb => sub {
$new->send(0);
$focus->send(0);
}
);
is($new->recv->{container}->{focused}, 0, 'Window "new" event received');
is($focus->recv->{container}->{focused}, 1, 'Window "focus" event received');
}
is(scalar @events, 2, 'Received 2 events');
is($events[0]->{container}->{focused}, 0, 'Window "new" event received');
is($events[1]->{container}->{focused}, 1, 'Window "focus" event received');
done_testing;