]> git.sur5r.net Git - i3/i3/blobdiff - testcases/t/166-assign.t
t/166-assign: check for i3-nagbar in the process hierarchy instead of sleep(1)
[i3/i3] / testcases / t / 166-assign.t
index 254616c5bc26130340c63930aec4e869004dff8a..8d05c05bf239de156f5cbd5225c1185b88a763f5 100644 (file)
@@ -1,10 +1,9 @@
 #!perl
 # vim:ts=4:sw=4:expandtab
-# !NO_I3_INSTANCE! will prevent complete-run.pl from starting i3
 #
 # Tests if assignments work
 #
-use i3test;
+use i3test i3_autostart => 0;
 use X11::XCB qw(PROP_MODE_REPLACE);
 
 # TODO: move to X11::XCB
@@ -31,10 +30,15 @@ sub open_special {
     my $wm_class = delete($args{wm_class}) || 'special';
     $args{name} //= 'special window';
 
-    return open_window(
+    # We use dont_map because i3 will not map the window on the current
+    # workspace. Thus, open_window would time out in wait_for_map (2 seconds).
+    my $window = open_window(
         %args,
         before_map => sub { set_wm_class($_->id, $wm_class, $wm_class) },
+        dont_map => 1,
     );
+    $window->map;
+    return $window;
 }
 
 #####################################################################
@@ -188,6 +192,22 @@ sleep 0.25;
 # ticket #501
 #####################################################################
 
+# Walks /proc to figure out whether a child process of $i3pid with the name
+# 'i3-nagbar' exists.
+sub i3nagbar_running {
+    my ($i3pid) = @_;
+
+    my @procfiles = grep { m,^/proc/[0-9]+$, } </proc/*>;
+    for my $path (@procfiles) {
+        open(my $fh, '<', "$path/stat") or next;
+        my $line = <$fh>;
+        close($fh);
+        my ($comm, $ppid) = ($line =~ /^[0-9]+ \(([^)]+)\) . ([0-9]+)/);
+        return 1 if $ppid == $i3pid && $comm eq 'i3-nagbar';
+    }
+    return 0;
+}
+
 $config = <<EOT;
 # i3 config file (v4)
 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
@@ -196,9 +216,11 @@ EOT
 
 $pid = launch_with_config($config);
 
-# TODO: replace this with checking the process hierarchy
-# XXX: give i3-nagbar some time to start up
-sleep 1;
+# Ensure that i3-nagbar is running. It should be started pretty quickly, so we
+# busy-loop with a short delay.
+while (!i3nagbar_running($pid)) {
+    sleep 0.05;
+}
 
 $tmp = fresh_workspace;