From 7baf620218ccb77c1fc27a6e879b9ab9ec5d43a2 Mon Sep 17 00:00:00 2001 From: Reno Reckling Date: Tue, 13 Sep 2016 20:26:32 +0300 Subject: [PATCH] make mumble vm test more robust This test should have a more robust retry loop and handles wrong focus on all windows. --- nixos/lib/test-driver/Machine.pm | 19 +++++-- nixos/tests/mumble.nix | 85 ++++++++++++++++++++++---------- 2 files changed, 75 insertions(+), 29 deletions(-) diff --git a/nixos/lib/test-driver/Machine.pm b/nixos/lib/test-driver/Machine.pm index 1a243918c22f..b9dad03e16f3 100644 --- a/nixos/lib/test-driver/Machine.pm +++ b/nixos/lib/test-driver/Machine.pm @@ -566,14 +566,25 @@ sub getWindowNames { } +sub hasWindow { + my ($self, $regexp) = @_; + my @names = $self->getWindowNames; + foreach my $n (@names) { + if ($n =~ /$regexp/) { + $self->log("match '$n' on '$regexp'"); + return 1; + } else { + $self->log("no match '$n' on '$regexp'"); + } + } +} + + sub waitForWindow { my ($self, $regexp) = @_; $self->nest("waiting for a window to appear", sub { retry sub { - my @names = $self->getWindowNames; - foreach my $n (@names) { - return 1 if $n =~ /$regexp/; - } + return $self->hasWindow($regexp) } }); } diff --git a/nixos/tests/mumble.nix b/nixos/tests/mumble.nix index 7959b85a0cf0..1c06ed10f4cb 100644 --- a/nixos/tests/mumble.nix +++ b/nixos/tests/mumble.nix @@ -33,34 +33,69 @@ in $client1->execute("mumble mumble://client1\@server/test &"); $client2->execute("mumble mumble://client2\@server/test &"); - # cancel client audio configuration - $client1->waitForWindow(qr/Audio Tuning Wizard/); - $client2->waitForWindow(qr/Audio Tuning Wizard/); - $server->sleep(5); # wait because mumble is slow to register event handlers - $client1->sendKeys("esc"); - $client2->sendKeys("esc"); + sub retry { + my ($coderef) = @_; + my $n; + for ($n = 0; $n < 900; $n++) { + return if &$coderef; + sleep 1; + } + die "action timed out after $n seconds"; + } - # cancel client cert configuration - $client1->waitForWindow(qr/Certificate Management/); - $client2->waitForWindow(qr/Certificate Management/); - $server->sleep(5); # wait because mumble is slow to register event handlers - $client1->sendKeys("esc"); - $client2->sendKeys("esc"); + my @clients = ($client1, $client2); + foreach my $cl (@clients) { + # cancel client audio configuration + my $audiore = qr/Audio Tuning Wizard/; + $cl->waitForWindow($audiore); + $cl->sleep(5); + $cl->nest("Cancel Audio Tuning Wizard", sub { + my $c = 0; + retry(sub { + return 1 if !$cl->hasWindow($audiore); + if ($c % 2 > 0) { + $cl->sendKeys("alt-tab"); + $cl->sleep(5); + } + $cl->sendKeys("esc"); + $c++; + }); + }); - # accept server certificate - $client1->waitForWindow(qr/^Mumble$/); - $client2->waitForWindow(qr/^Mumble$/); - $server->sleep(5); # wait because mumble is slow to register event handlers - $client1->sendChars("y"); - $client2->sendChars("y"); - $server->sleep(5); # wait because mumble is slow to register event handlers + # cancel client cert configuration + my $certre = qr/Certificate Management/; + $cl->waitForWindow($certre); + $cl->sleep(5); + $cl->nest("Cancel Certificate Management", sub { + my $c = 0; + retry(sub { + return 1 if !$cl->hasWindow($certre); + if ($c % 2 > 0) { + $cl->sendKeys("alt-tab"); + $cl->sleep(5); + } + $cl->sendKeys("esc"); + $c++; + }); + }); - # sometimes the wrong of the 2 windows is focused, we switch focus and try pressing "y" again - $client1->sendKeys("alt-tab"); - $client2->sendKeys("alt-tab"); - $server->sleep(5); # wait because mumble is slow to register event handlers - $client1->sendChars("y"); - $client2->sendChars("y"); + # accept server certificate + my $acceptre = qr/^Mumble$/; + $cl->waitForWindow($acceptre); + $cl->sleep(5); + $cl->nest("Accept Server Certificate", sub { + my $c = 0; + retry(sub { + return 1 if !$cl->hasWindow($acceptre); + if ($c % 2 > 0) { + $cl->sendKeys("alt-tab"); + $cl->sleep(5); + } + $cl->sendChars("y"); + $c++; + }); + }); + } # Find clients in logs $server->waitUntilSucceeds("grep -q 'client1' /var/log/murmur/murmurd.log");