@@ -115,7 +115,9 @@ func TestLedgerReleaseResources(t *testing.T) {
115
115
instName string
116
116
entry * entry
117
117
cpuUsed int64
118
+ a1Used int64
118
119
wantCPUUsed int64
120
+ wantA1Used int64
119
121
wantErr bool
120
122
}{
121
123
{
@@ -126,7 +128,9 @@ func TestLedgerReleaseResources(t *testing.T) {
126
128
vCPUCount : 10 ,
127
129
},
128
130
cpuUsed : 20 ,
131
+ a1Used : 0 ,
129
132
wantCPUUsed : 10 ,
133
+ wantA1Used : 0 ,
130
134
wantErr : false ,
131
135
},
132
136
{
@@ -137,14 +141,45 @@ func TestLedgerReleaseResources(t *testing.T) {
137
141
vCPUCount : 10 ,
138
142
},
139
143
cpuUsed : 20 ,
144
+ a1Used : 0 ,
140
145
wantCPUUsed : 20 ,
146
+ wantA1Used : 0 ,
147
+ wantErr : true ,
148
+ },
149
+ {
150
+ desc : "success-with-a1-instance" ,
151
+ instName : "inst-x" ,
152
+ entry : & entry {
153
+ instanceName : "inst-x" ,
154
+ vCPUCount : 10 ,
155
+ instanceType : a1MetalInstance ,
156
+ },
157
+ cpuUsed : 20 ,
158
+ a1Used : 1 ,
159
+ wantCPUUsed : 10 ,
160
+ wantA1Used : 0 ,
161
+ wantErr : false ,
162
+ },
163
+ {
164
+ desc : "entry-not-found-with-a1-instance" ,
165
+ instName : "inst-x" ,
166
+ entry : & entry {
167
+ instanceName : "inst-w" ,
168
+ vCPUCount : 10 ,
169
+ instanceType : a1MetalInstance ,
170
+ },
171
+ cpuUsed : 20 ,
172
+ a1Used : 1 ,
173
+ wantCPUUsed : 20 ,
174
+ wantA1Used : 1 ,
141
175
wantErr : true ,
142
176
},
143
177
}
144
178
for _ , tc := range testCases {
145
179
t .Run (tc .desc , func (t * testing.T ) {
146
180
l := & ledger {
147
- cpuUsed : tc .cpuUsed ,
181
+ cpuUsed : tc .cpuUsed ,
182
+ instanceA1Used : tc .a1Used ,
148
183
entries : map [string ]* entry {
149
184
tc .entry .instanceName : tc .entry ,
150
185
},
@@ -156,62 +191,125 @@ func TestLedgerReleaseResources(t *testing.T) {
156
191
if l .cpuUsed != tc .wantCPUUsed {
157
192
t .Errorf ("ledger.cpuUsed = %d; wanted %d" , l .cpuUsed , tc .wantCPUUsed )
158
193
}
194
+ if l .instanceA1Used != tc .wantA1Used {
195
+ t .Errorf ("ledger.instanceA1Used = %d; wanted %d" , l .instanceA1Used , tc .wantA1Used )
196
+ }
159
197
})
160
198
}
161
199
}
162
200
163
- func TestLedgerAllocateCPU (t * testing.T ) {
201
+ func TestLedgerAllocateResources (t * testing.T ) {
164
202
testCases := []struct {
165
203
desc string
166
204
numCPU int64
167
205
cpuLimit int64
168
206
cpuUsed int64
207
+ a1Used int64
208
+ a1Limit int64
169
209
instName string
210
+ instType string
170
211
wantReserve bool
171
212
wantCPUUsed int64
213
+ wantA1Used int64
172
214
}{
173
215
{
174
216
desc : "reservation-success" ,
175
217
numCPU : 10 ,
176
218
cpuLimit : 10 ,
177
219
cpuUsed : 0 ,
220
+ a1Used : 0 ,
221
+ a1Limit : 1 ,
178
222
instName : "chacha" ,
223
+ instType : "x.type" ,
179
224
wantReserve : true ,
180
225
wantCPUUsed : 10 ,
226
+ wantA1Used : 0 ,
181
227
},
182
228
{
183
229
desc : "failed-to-reserve" ,
230
+ a1Used : 0 ,
231
+ a1Limit : 1 ,
184
232
numCPU : 10 ,
185
233
cpuLimit : 5 ,
186
234
cpuUsed : 0 ,
187
235
instName : "pasa" ,
236
+ instType : "x.type" ,
188
237
wantReserve : false ,
189
238
wantCPUUsed : 0 ,
239
+ wantA1Used : 0 ,
190
240
},
191
241
{
192
242
desc : "invalid-cpu-count" ,
243
+ a1Used : 0 ,
244
+ a1Limit : 1 ,
193
245
numCPU : 0 ,
194
246
cpuLimit : 50 ,
195
247
cpuUsed : 20 ,
196
248
instName : "double" ,
249
+ instType : "x.type" ,
197
250
wantReserve : false ,
198
251
wantCPUUsed : 20 ,
252
+ wantA1Used : 0 ,
253
+ },
254
+ {
255
+ desc : "reservation-success with a1.metal instance" ,
256
+ numCPU : 10 ,
257
+ cpuLimit : 10 ,
258
+ cpuUsed : 0 ,
259
+ a1Used : 0 ,
260
+ a1Limit : 1 ,
261
+ instName : "chacha" ,
262
+ instType : a1MetalInstance ,
263
+ wantReserve : true ,
264
+ wantCPUUsed : 10 ,
265
+ wantA1Used : 1 ,
266
+ },
267
+ {
268
+ desc : "failed-to-reserve with a1.metal instance" ,
269
+ a1Used : 0 ,
270
+ a1Limit : 1 ,
271
+ numCPU : 10 ,
272
+ cpuLimit : 5 ,
273
+ cpuUsed : 0 ,
274
+ instName : "pasa" ,
275
+ instType : a1MetalInstance ,
276
+ wantReserve : false ,
277
+ wantCPUUsed : 0 ,
278
+ wantA1Used : 0 ,
279
+ },
280
+ {
281
+ desc : "invalid-cpu-count with a1.metal instance" ,
282
+ a1Used : 0 ,
283
+ a1Limit : 10 ,
284
+ numCPU : 0 ,
285
+ cpuLimit : 50 ,
286
+ cpuUsed : 20 ,
287
+ instName : "double" ,
288
+ instType : a1MetalInstance ,
289
+ wantReserve : false ,
290
+ wantCPUUsed : 20 ,
291
+ wantA1Used : 0 ,
199
292
},
200
293
}
201
294
for _ , tc := range testCases {
202
295
t .Run (tc .desc , func (t * testing.T ) {
203
296
l := & ledger {
204
- entries : make (map [string ]* entry ),
205
- cpuLimit : tc .cpuLimit ,
206
- cpuUsed : tc .cpuUsed ,
297
+ entries : make (map [string ]* entry ),
298
+ cpuLimit : tc .cpuLimit ,
299
+ cpuUsed : tc .cpuUsed ,
300
+ instanceA1Limit : tc .a1Limit ,
301
+ instanceA1Used : tc .a1Used ,
207
302
}
208
- gotReserve := l .allocateCPU (tc .numCPU , tc .instName )
303
+ gotReserve := l .allocateResources (tc .numCPU , tc .instName , tc . instType )
209
304
if gotReserve != tc .wantReserve {
210
- t .Errorf ("ledger.allocateCPU (%d) = %v, want %v" , tc .numCPU , gotReserve , tc .wantReserve )
305
+ t .Errorf ("ledger.allocateResources (%d) = %v, want %v" , tc .numCPU , gotReserve , tc .wantReserve )
211
306
}
212
307
if l .cpuUsed != tc .wantCPUUsed {
213
308
t .Errorf ("ledger.cpuUsed = %d; want %d" , l .cpuUsed , tc .wantCPUUsed )
214
309
}
310
+ if l .instanceA1Used != tc .wantA1Used {
311
+ t .Errorf ("ledger.instanceA1Used = %d; want %d" , l .instanceA1Used , tc .wantA1Used )
312
+ }
215
313
if _ , ok := l .entries [tc .instName ]; tc .wantReserve && ! ok {
216
314
t .Fatalf ("ledger.entries[%s] = nil; want it to exist" , tc .instName )
217
315
}
0 commit comments