@@ -6,19 +6,69 @@ import (
66
77 "github.com/stretchr/testify/assert"
88 "github.com/stretchr/testify/require"
9+ "k8s.io/apimachinery/pkg/api/resource"
910
11+ schedulerconfiguration "github.com/armadaproject/armada/internal/scheduler/configuration"
12+ "github.com/armadaproject/armada/internal/scheduler/internaltypes"
1013 "github.com/armadaproject/armada/pkg/bidstore"
1114)
1215
16+ var testResourceListFactory , _ = internaltypes .NewResourceListFactory (
17+ []schedulerconfiguration.ResourceType {
18+ {Name : "memory" , Resolution : resource .MustParse ("1" )},
19+ {Name : "cpu" , Resolution : resource .MustParse ("1m" )},
20+ {Name : "nvidia.com/gpu" , Resolution : resource .MustParse ("1m" )},
21+ },
22+ []schedulerconfiguration.FloatingResourceConfig {},
23+ )
24+
1325func TestConvert (t * testing.T ) {
1426 tests := map [string ]struct {
1527 input * bidstore.RetrieveBidsResponse
1628 expected BidPriceSnapshot
1729 }{
1830 "empty input" : {
1931 input : & bidstore.RetrieveBidsResponse {},
32+ expected : BidPriceSnapshot {
33+ Bids : make (map [PriceKey ]map [string ]Bid ),
34+ ResourceUnits : map [string ]internaltypes.ResourceList {},
35+ },
36+ },
37+ "resourceUnit" : {
38+ input : & bidstore.RetrieveBidsResponse {
39+ PoolResourceUnits : map [string ]* bidstore.ResourceShape {
40+ "pool1" : {
41+ Resources : map [string ]* resource.Quantity {
42+ "cpu" : mustParsePtr ("1" ),
43+ "memory" : mustParsePtr ("1Gi" ),
44+ },
45+ },
46+ "pool2" : {
47+ Resources : map [string ]* resource.Quantity {
48+ "cpu" : mustParsePtr ("2" ),
49+ "memory" : mustParsePtr ("2Gi" ),
50+ "nvidia.com/gpu" : mustParsePtr ("1" ),
51+ },
52+ },
53+ },
54+ },
2055 expected : BidPriceSnapshot {
2156 Bids : make (map [PriceKey ]map [string ]Bid ),
57+ ResourceUnits : map [string ]internaltypes.ResourceList {
58+ "pool1" : testResourceListFactory .FromNodeProto (
59+ map [string ]* resource.Quantity {
60+ "cpu" : mustParsePtr ("1" ),
61+ "memory" : mustParsePtr ("1Gi" ),
62+ },
63+ ),
64+ "pool2" : testResourceListFactory .FromNodeProto (
65+ map [string ]* resource.Quantity {
66+ "cpu" : mustParsePtr ("2" ),
67+ "memory" : mustParsePtr ("2Gi" ),
68+ "nvidia.com/gpu" : mustParsePtr ("1" ),
69+ },
70+ ),
71+ },
2272 },
2373 },
2474 "single bid with both phases" : {
@@ -55,6 +105,7 @@ func TestConvert(t *testing.T) {
55105 },
56106 },
57107 },
108+ ResourceUnits : map [string ]internaltypes.ResourceList {},
58109 },
59110 },
60111 "uses fallback if direct bid is missing" : {
@@ -63,7 +114,7 @@ func TestConvert(t *testing.T) {
63114 "queue1" : {
64115 PoolBids : map [string ]* bidstore.PoolBids {
65116 "pool1" : {
66- FallbackBid : & bidstore.PriceBandBids {
117+ FallbackBids : & bidstore.PriceBandBids {
67118 PricingPhaseBids : []* bidstore.PricingPhaseBid {
68119 CreateQueuedBid (5.0 ),
69120 CreateRunningBid (10.0 ),
@@ -158,13 +209,14 @@ func TestConvert(t *testing.T) {
158209 },
159210 },
160211 },
212+ ResourceUnits : map [string ]internaltypes.ResourceList {},
161213 },
162214 },
163215 }
164216
165217 for name , tc := range tests {
166218 t .Run (name , func (t * testing.T ) {
167- actual := convert (tc .input )
219+ actual := convert (tc .input , testResourceListFactory )
168220
169221 // Remove non-deterministic time field before comparison
170222 require .False (t , actual .Timestamp .IsZero (), "timestamp should be set" )
@@ -192,3 +244,8 @@ func CreateRunningBid(p float64) *bidstore.PricingPhaseBid {
192244 },
193245 }
194246}
247+
248+ func mustParsePtr (qty string ) * resource.Quantity {
249+ q := resource .MustParse (qty )
250+ return & q
251+ }
0 commit comments