12199: Derate advertised node sizes by 5%.
[arvados.git] / services / dispatchcloud / node_size_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package dispatchcloud
6
7 import (
8         "git.curoverse.com/arvados.git/sdk/go/arvados"
9         check "gopkg.in/check.v1"
10 )
11
12 var _ = check.Suite(&NodeSizeSuite{})
13
14 type NodeSizeSuite struct{}
15
16 func (*NodeSizeSuite) TestChooseNotConfigured(c *check.C) {
17         _, err := ChooseInstanceType(&arvados.Cluster{}, &arvados.Container{
18                 RuntimeConstraints: arvados.RuntimeConstraints{
19                         RAM:   1234567890,
20                         VCPUs: 2,
21                 },
22         })
23         c.Check(err, check.Equals, ErrInstanceTypesNotConfigured)
24 }
25
26 func (*NodeSizeSuite) TestChooseUnsatisfiable(c *check.C) {
27         for _, rc := range []arvados.RuntimeConstraints{
28                 {RAM: 9876543210, VCPUs: 2},
29                 {RAM: 1234567890, VCPUs: 20},
30                 {RAM: 1234567890, VCPUs: 2, KeepCacheRAM: 9876543210},
31         } {
32                 _, err := ChooseInstanceType(&arvados.Cluster{InstanceTypes: []arvados.InstanceType{
33                         {Price: 1.1, RAM: 1000000000, VCPUs: 2, Name: "small1"},
34                         {Price: 2.2, RAM: 2000000000, VCPUs: 4, Name: "small2"},
35                         {Price: 4.4, RAM: 4000000000, VCPUs: 8, Name: "small4"},
36                 }}, &arvados.Container{RuntimeConstraints: rc})
37                 c.Check(err, check.Equals, ErrConstraintsNotSatisfiable)
38         }
39 }
40
41 func (*NodeSizeSuite) TestChoose(c *check.C) {
42         for _, menu := range [][]arvados.InstanceType{
43                 {
44                         {Price: 4.4, RAM: 4000000000, VCPUs: 8, Name: "costly"},
45                         {Price: 2.2, RAM: 2000000000, VCPUs: 4, Name: "best"},
46                         {Price: 1.1, RAM: 1000000000, VCPUs: 2, Name: "small"},
47                 },
48                 {
49                         {Price: 4.4, RAM: 4000000000, VCPUs: 8, Name: "costly"},
50                         {Price: 2.2, RAM: 2000000000, VCPUs: 4, Name: "goodenough"},
51                         {Price: 2.2, RAM: 4000000000, VCPUs: 4, Name: "best"},
52                         {Price: 1.1, RAM: 1000000000, VCPUs: 2, Name: "small"},
53                 },
54                 {
55                         {Price: 1.1, RAM: 1000000000, VCPUs: 2, Name: "small"},
56                         {Price: 2.2, RAM: 2000000000, VCPUs: 4, Name: "goodenough"},
57                         {Price: 2.2, RAM: 4000000000, VCPUs: 4, Name: "best"},
58                         {Price: 4.4, RAM: 4000000000, VCPUs: 8, Name: "costly"},
59                 },
60         } {
61                 best, err := ChooseInstanceType(&arvados.Cluster{InstanceTypes: menu}, &arvados.Container{
62                         RuntimeConstraints: arvados.RuntimeConstraints{
63                                 VCPUs:        2,
64                                 RAM:          987654321,
65                                 KeepCacheRAM: 123456789,
66                         },
67                 })
68                 c.Check(err, check.IsNil)
69                 c.Check(best.Name, check.Equals, "best")
70                 c.Check(best.RAM >= 1234567890, check.Equals, true)
71                 c.Check(best.VCPUs >= 2, check.Equals, true)
72         }
73 }