]> git.sur5r.net Git - i3/i3/blob - testcases/t/298-ipc-misbehaving-connection.t
Kill misbehaving subscribed clients instead of hanging
[i3/i3] / testcases / t / 298-ipc-misbehaving-connection.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 that i3 will not hang if a connected client stops reading from its
18 # subscription socket and that the client is killed after a delay.
19 # Ticket: #2999
20 # Bug still in: 4.15-180-g715cea61
21 use i3test i3_config => <<EOT;
22 # i3 config file (v4)
23 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
24 # Set the timeout to 500ms to reduce the duration of this test.
25 ipc_kill_timeout 500
26 EOT
27
28 # Manually connect to i3 so that we can choose to not read events
29 use IO::Socket::UNIX;
30 my $sock = IO::Socket::UNIX->new(Peer => get_socket_path());
31 my $magic = "i3-ipc";
32 my $payload = '["workspace"]';
33 my $message = $magic . pack("LL", length($payload), 2) . $payload;
34 print $sock $message;
35
36 # Constantly switch between 2 workspaces to generate events.
37 fresh_workspace;
38 open_window;
39 fresh_workspace;
40 open_window;
41
42 eval {
43     local $SIG{ALRM} = sub { die "Timeout\n" };
44     # 500 is an arbitrarily large number to make sure that the socket becomes
45     # non-writeable.
46     for (my $i = 0; $i < 500; $i++) {
47         alarm 1;
48         cmd 'workspace back_and_forth';
49         alarm 0;
50     }
51 };
52 ok(!$@, 'i3 didn\'t hang');
53
54 # Wait for connection timeout
55 sleep 1;
56
57 use IO::Select;
58 my $s = IO::Select->new($sock);
59 my $reached_eof = 0;
60 while ($s->can_read(0.05)) {
61     if (read($sock, my $buffer, 100) == 0) {
62         $reached_eof = 1;
63         last;
64     }
65 }
66 ok($reached_eof, 'socket connection closed');
67
68 close $sock;
69 done_testing;