From 730527b83654651993b5623cbfe9243920eac937 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Tue, 21 Apr 2015 13:38:34 +0000 Subject: [PATCH] Fix non-deterministic user acceptance tests --- features/layout/manage.feature | 2 +- features/layout/protocol.feature | 2 +- features/layout/unmanage.feature | 4 ++-- features/manager/unmanage.feature | 4 ++-- features/steps/x_steps.rb | 25 +++++++++++++------------ lib/uh/wm/testing/acceptance_helpers.rb | 7 ++++--- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/features/layout/manage.feature b/features/layout/manage.feature index f7dc6e7..7c60227 100644 --- a/features/layout/manage.feature +++ b/features/layout/manage.feature @@ -8,5 +8,5 @@ Feature: layout client management Then the window must be mapped Scenario: focuses new client window - When a window requests to be mapped + When a window is mapped Then the window must be focused diff --git a/features/layout/protocol.feature b/features/layout/protocol.feature index 3d452cc..5df4e09 100644 --- a/features/layout/protocol.feature +++ b/features/layout/protocol.feature @@ -30,6 +30,6 @@ Feature: layout protocol Scenario: tells the layout to unmanage a client with #remove message Given uhwm is running with options -v -r./layout -l Layout - And a window is managed + And a window is mapped When the window is unmapped Then the output must contain "testing_#remove_XClient/default" diff --git a/features/layout/unmanage.feature b/features/layout/unmanage.feature index 9baf703..dcb950e 100644 --- a/features/layout/unmanage.feature +++ b/features/layout/unmanage.feature @@ -2,8 +2,8 @@ Feature: layout client unmanagement Background: Given uhwm is running - And a first window is managed - And a second window is managed + And a first window is mapped + And a second window is mapped Scenario: maps another window When the second window is unmapped diff --git a/features/manager/unmanage.feature b/features/manager/unmanage.feature index d8be9f3..60e5c7b 100644 --- a/features/manager/unmanage.feature +++ b/features/manager/unmanage.feature @@ -2,10 +2,10 @@ Feature: manager client unmanagement Background: Given uhwm is running - And a window is managed + And a window is mapped Scenario: logs when a new client is unmanaged - When the window requests to be unmapped + When the window is unmapped Then the output must match /unmanag.+xclient/i Scenario: unmanages client on destroy notify X events diff --git a/features/steps/x_steps.rb b/features/steps/x_steps.rb index be0faf8..13fe3a6 100644 --- a/features/steps/x_steps.rb +++ b/features/steps/x_steps.rb @@ -1,7 +1,8 @@ -Given /^a(?:\s(\w+))? window is managed$/ do |ident| - ident ||= :default +Given /^a(?:\s(\w+))? window is mapped$/ do |ident| x_client(ident).map.sync - uhwm_wait_output /manag.+#{x_client(ident).name}/i + timeout_until 'window not mapped after %d seconds' do + x_window_map_state(x_client(ident).window_id) == 'IsViewable' + end end When /^I press the ([^ ]+) keys?$/ do |keys| @@ -16,14 +17,11 @@ When /^a window requests to be mapped (\d+) times$/ do |times| x_client.map times: times.to_i end -When /^the window requests to be unmapped$/ do - x_client.unmap.sync -end - When /^the(?:\s(\w+))? window is unmapped$/ do |ident| - ident ||= :default x_client(ident).unmap.sync - uhwm_wait_output /unmanag.+#{x_client(ident).name}/i + timeout_until 'window not unmapped after %d seconds' do + x_window_map_state(x_client(ident).window_id) == 'IsUnMapped' + end end When /^the window is destroyed$/ do @@ -36,12 +34,15 @@ Then /^it must connect to X display$/ do end Then /^the(?:\s(\w+))? window must be mapped$/ do |ident| - ident ||= :default - expect(x_window_map_state x_client(ident).window_id).to eq 'IsViewable' + timeout_until 'window not mapped after %d seconds' do + x_window_map_state(x_client(ident).window_id) == 'IsViewable' + end end Then /^the window must be focused$/ do - expect(x_focused_window_id).to eq x_client.window_id + timeout_until 'window not focused after %d seconds' do + x_focused_window_id == x_client.window_id + end end Then /^the input event mask must include (.+)$/ do |mask| diff --git a/lib/uh/wm/testing/acceptance_helpers.rb b/lib/uh/wm/testing/acceptance_helpers.rb index 84aa80f..d63f168 100644 --- a/lib/uh/wm/testing/acceptance_helpers.rb +++ b/lib/uh/wm/testing/acceptance_helpers.rb @@ -64,7 +64,8 @@ module Uh @other_wm end - def x_client ident = :default + def x_client ident = nil + ident ||= :default @x_clients ||= {} @x_clients[ident] ||= XClient.new(ident) end @@ -103,7 +104,7 @@ module Uh private - def timeout_until + def timeout_until message = 'condition not met after %d seconds' timeout = ENV.key?('UHWMTEST_TIMEOUT') ? ENV['UHWMTEST_TIMEOUT'].to_i : TIMEOUT_DEFAULT @@ -114,7 +115,7 @@ module Uh end end rescue Timeout::Error - fail TimeoutError.new('execution expired', timeout) + fail TimeoutError.new(message % timeout, timeout) end