t10_timeout.t 2.5 KB
Newer Older
Francesc Guasch's avatar
Francesc Guasch committed
1
2
3
4
5
6
7
8
9
10
11
use warnings;
use strict;

use Carp qw(confess);
use Data::Dumper;
use IPC::Run3;
use Test::More;

use lib 't/lib';
use Test::Ravada;

Francesc Guasch's avatar
Francesc Guasch committed
12
my $RVD_BACK = rvd_back();
Francesc Guasch's avatar
Francesc Guasch committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
my $USER;

$USER = create_user('foo','bar');

######################################################

sub test_run_timeout {
    my $vm_name = shift;
    my $domain = create_domain($vm_name, user_admin)
        or return;

    my $timeout = 5;

    $domain->run_timeout($timeout);


    is($domain->run_timeout(),$timeout);
    $domain->prepare_base(user_admin);

    $domain->is_public(1);
    ok($domain->is_public());
    ok($domain->is_base());

    my $domain_f = rvd_front->search_domain($domain->name);
    is($domain_f->run_timeout(),$timeout);
    is($domain_f->is_public(),1);

    my $clone = $domain->clone(user => $USER, name => new_domain_name());

    is($clone->run_timeout(),$timeout);

    $clone->start(user => $USER);
Francesc Guasch's avatar
Francesc Guasch committed
45
    is(scalar($clone->list_requests(1)),1) or exit;
Francesc Guasch's avatar
Francesc Guasch committed
46
47

    is($clone->is_active,1);
Francesc Guasch's avatar
Francesc Guasch committed
48
    rvd_back->_process_all_requests_dont_fork();
Francesc Guasch's avatar
Francesc Guasch committed
49
    is($clone->is_active,1);
Francesc Guasch's avatar
Francesc Guasch committed
50
51
    for ( 1 .. $timeout + 60 ) {
        last if !$clone->is_active || ! scalar($clone->list_requests(1));
Francesc Guasch's avatar
Francesc Guasch committed
52
        sleep 1;
Francesc Guasch's avatar
Francesc Guasch committed
53
        rvd_back->_process_all_requests_dont_fork();
Francesc Guasch's avatar
Francesc Guasch committed
54
    }
Francesc Guasch's avatar
Francesc Guasch committed
55
    is($clone->is_active,0, "Expecting ".$clone->name." timed out shutdown") or exit;
Francesc Guasch's avatar
Francesc Guasch committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

    $clone->remove(user_admin);
    $domain->remove(user_admin);
}

sub test_run_timeout_propagate {
    my $vm_name = shift;

    my $domain = create_domain($vm_name, user_admin) or return;

    my $timeout = 5;

    $domain->run_timeout($timeout);
    $domain->prepare_base(user_admin);

    $domain->is_public(1);

    my $clone = $domain->clone(user => $USER, name => new_domain_name());

    is($clone->run_timeout(),$timeout);

    my $timeout2 = 7;
    $domain->run_timeout($timeout2);

    my $clone2 = rvd_front->search_domain($clone->name);
    is($clone2->run_timeout(),$timeout2);

    $clone->remove(user_admin);
    $domain->remove(user_admin);
}

######################################################
clean();

for my $vm_name ( @{rvd_front->list_vm_types},'Void') {

    my $vm = rvd_back->search_vm($vm_name);

    SKIP: {

        my $msg = "SKIPPED: No virtual managers found";
        if ($vm && $vm_name =~ /kvm/i && $>) {
            $msg = "SKIPPED: Test must run as root";
            $vm = undef;
        }

        skip($msg,10)   if !$vm;
        diag("Testing timeout for $vm_name");

        test_run_timeout($vm_name);
        test_run_timeout_propagate($vm_name);
    }
}

clean();
done_testing();