]>
git.proxmox.com Git - proxmox-perl-rs.git/blob - pve-rs/test/resource_scheduling.pl
8 use PVE
::RS
::ResourceScheduling
::Static
;
11 my $static = PVE
::RS
::ResourceScheduling
::Static-
>new();
12 is(scalar($static->list_nodes()->@*), 0, 'node list empty');
13 $static->add_node("A", 10, 100_000_000_000);
14 is(scalar($static->list_nodes()->@*), 1, '1 node added');
15 $static->add_node("B", 20, 200_000_000_000);
16 is(scalar($static->list_nodes()->@*), 2, '2nd node');
17 $static->add_node("C", 30, 300_000_000_000);
18 is(scalar($static->list_nodes()->@*), 3, '3rd node');
19 $static->remove_node("C");
20 is(scalar($static->list_nodes()->@*), 2, '3rd removed should be 2');
21 ok
($static->contains_node("A"), 'should contain a node A');
22 ok
($static->contains_node("B"), 'should contain a node B');
23 ok
(!$static->contains_node("C"), 'should not contain a node C');
27 my $static = PVE
::RS
::ResourceScheduling
::Static-
>new();
28 $static->add_node("A", 10, 100_000_000_000);
29 $static->add_node("B", 20, 200_000_000_000);
33 maxmem
=> 20_000_000_000,
36 for (my $i = 0; $i < 15; $i++) {
37 my $score_list = $static->score_nodes_to_start_service($service);
40 my $scores = { map { $_->[0] => -$_->[1] } $score_list->@* };
42 $scores->{$a} <=> $scores->{$b} || $a cmp $b
46 is($nodes[0], "A", 'first should be A');
47 is($nodes[1], "B", 'second should be A');
49 is($nodes[0], "B", 'first should be B');
50 is($nodes[1], "A", 'second should be A');
53 $static->add_service_usage_to_node($nodes[0], $service);
57 sub test_overcommitted
{
58 my $static = PVE
::RS
::ResourceScheduling
::Static-
>new();
59 $static->add_node("A", 4, 4_102_062_080);
60 $static->add_node("B", 4, 4_102_062_080);
61 $static->add_node("C", 4, 4_102_053_888);
62 $static->add_node("D", 4, 4_102_053_888);
66 maxmem
=> 536_870_912,
69 $static->add_service_usage_to_node("A", $service);
70 $static->add_service_usage_to_node("A", $service);
71 $static->add_service_usage_to_node("A", $service);
72 $static->add_service_usage_to_node("B", $service);
73 $static->add_service_usage_to_node("A", $service);
75 my $score_list = $static->score_nodes_to_start_service($service);
78 my $scores = { map { $_->[0] => -$_->[1] } $score_list->@* };
80 $scores->{$a} <=> $scores->{$b} || $a cmp $b
83 is($nodes[0], "C", 'first should be C');
84 is($nodes[1], "D", 'second should be D');
85 is($nodes[2], "B", 'third should be B');
86 is($nodes[3], "A", 'fourth should be A');