]> git.sur5r.net Git - i3/i3/blob - testcases/t/289-ipc-shutdown-event.t
tests: replace http:// with https:// where appropriate
[i3/i3] / testcases / t / 289-ipc-shutdown-event.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • https://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
17 # Test the ipc shutdown event. This event is triggered when the connection to
18 # the ipc is about to shutdown because of a user action such as with a
19 # `restart` or `exit` command. The `change` field indicates why the ipc is
20 # shutting down. It can be either "restart" or "exit".
21 #
22 # Ticket: #2318
23 # Bug still in: 4.12-46-g2123888
24 use i3test;
25
26 SKIP: {
27     skip "AnyEvent::I3 too old (need >= 0.17)", 1 if $AnyEvent::I3::VERSION < 0.17;
28
29 my $i3 = i3(get_socket_path());
30 $i3->connect->recv;
31
32 my $cv = AE::cv;
33 my $timer = AE::timer 0.5, 0, sub { $cv->send(0); };
34
35 $i3->subscribe({
36         shutdown => sub {
37             $cv->send(shift);
38         }
39     })->recv;
40
41 cmd 'restart';
42
43 my $e = $cv->recv;
44
45 diag "Event:\n", Dumper($e);
46 ok($e, 'the shutdown event should emit when the ipc is restarted by command');
47 is($e->{change}, 'restart', 'the `change` field should tell the reason for the shutdown');
48
49 # restarting kills the ipc client so we have to make a new one
50 $i3 = i3(get_socket_path());
51 $i3->connect->recv;
52
53 $cv = AE::cv;
54 $timer = AE::timer 0.5, 0, sub { $cv->send(0); };
55
56 $i3->subscribe({
57         shutdown => sub {
58             $cv->send(shift);
59         }
60     })->recv;
61
62 cmd 'exit';
63
64 $e = $cv->recv;
65
66 diag "Event:\n", Dumper($e);
67 ok($e, 'the shutdown event should emit when the ipc is exited by command');
68 is($e->{change}, 'exit', 'the `change` field should tell the reason for the shutdown');
69 }
70
71 done_testing;