@@ -3,10 +3,13 @@ package disks
3
3
import (
4
4
"context"
5
5
"testing"
6
+ "time"
6
7
7
8
"github.com/stretchr/testify/mock"
8
9
"github.com/stretchr/testify/require"
10
+ "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/clients/nbs"
9
11
nbs_mocks "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/clients/nbs/mocks"
12
+ performance_config "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/performance/config"
10
13
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/resources"
11
14
storage_mocks "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/resources/mocks"
12
15
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/services/disks/protos"
@@ -40,20 +43,30 @@ func testDeleteDiskTaskRun(t *testing.T, sync bool) {
40
43
state : & protos.DeleteDiskTaskState {},
41
44
}
42
45
46
+ diskMeta := & resources.DiskMeta {
47
+ ZoneID : "zone" ,
48
+ Kind : "ssd" ,
49
+ DeleteTaskID : "toplevel_task_id" ,
50
+ }
51
+ if sync {
52
+ storage .On (
53
+ "GetDiskMeta" ,
54
+ ctx ,
55
+ "disk" ,
56
+ ).Return (diskMeta , nil ).Once ()
57
+ }
43
58
storage .On (
44
59
"DeleteDisk" ,
45
60
ctx ,
46
61
"disk" ,
47
62
"toplevel_task_id" ,
48
63
mock .Anything ,
49
- ).Return (& resources.DiskMeta {
50
- ZoneID : "zone" ,
51
- DeleteTaskID : "toplevel_task_id" ,
52
- }, nil )
64
+ ).Return (diskMeta , nil ).Once ()
53
65
storage .On ("DiskDeleted" , ctx , "disk" , mock .Anything ).Return (nil )
54
66
55
67
nbsFactory .On ("GetClient" , ctx , "zone" ).Return (nbsClient , nil )
56
68
if sync {
69
+ nbsClient .On ("Describe" , ctx , "disk" ).Return (nbs.DiskParams {}, nil )
57
70
nbsClient .On ("DeleteSync" , ctx , "disk" ).Return (nil )
58
71
} else {
59
72
nbsClient .On ("Delete" , ctx , "disk" ).Return (nil )
@@ -112,6 +125,7 @@ func TestDeleteDiskTaskRunWithDiskCreatedFromImage(t *testing.T) {
112
125
).Return (& resources.DiskMeta {
113
126
ZoneID : "zone" ,
114
127
SrcImageID : "image" ,
128
+ Kind : "ssd" ,
115
129
DeleteTaskID : "toplevel_task_id" ,
116
130
}, nil )
117
131
storage .On ("DiskDeleted" , ctx , "disk" , mock .Anything ).Return (nil )
@@ -171,6 +185,7 @@ func TestDeleteDiskTaskCancel(t *testing.T) {
171
185
mock .Anything ,
172
186
).Return (& resources.DiskMeta {
173
187
ZoneID : "zone" ,
188
+ Kind : "ssd" ,
174
189
SrcImageID : "image" ,
175
190
DeleteTaskID : "toplevel_task_id" ,
176
191
}, nil )
@@ -234,3 +249,147 @@ func TestDeleteDiskTaskWithNonExistentDisk(t *testing.T) {
234
249
mock .AssertExpectationsForObjects (t , storage , scheduler , poolService , nbsFactory , execCtx )
235
250
require .NoError (t , err )
236
251
}
252
+
253
+ func testDeleteDiskTaskEstimatedInflightDurationForLocalDisks (
254
+ t * testing.T ,
255
+ sync bool ,
256
+ diskKind types.DiskKind ,
257
+ expectedEstimatedInflightDuration time.Duration ,
258
+ ) {
259
+ ctx := context .Background ()
260
+
261
+ SSDLocalDiskDeletingBandwidthMiBs := uint64 (100 )
262
+ HDDLocalDiskDeletingBandwidthMiBs := uint64 (10 )
263
+ performanceConfig := & performance_config.PerformanceConfig {
264
+ SSDLocalDiskDeletingBandwidthMiBs : & SSDLocalDiskDeletingBandwidthMiBs ,
265
+ HDDLocalDiskDeletingBandwidthMiBs : & HDDLocalDiskDeletingBandwidthMiBs ,
266
+ }
267
+ storage := storage_mocks .NewStorageMock ()
268
+ scheduler := tasks_mocks .NewSchedulerMock ()
269
+ poolService := pools_mocks .NewServiceMock ()
270
+ nbsFactory := nbs_mocks .NewFactoryMock ()
271
+ nbsClient := nbs_mocks .NewClientMock ()
272
+ execCtx := newExecutionContextMock ()
273
+
274
+ disk := & types.Disk {DiskId : "disk" }
275
+ request := & protos.DeleteDiskRequest {Disk : disk , Sync : sync }
276
+
277
+ task := & deleteDiskTask {
278
+ performanceConfig : performanceConfig ,
279
+ storage : storage ,
280
+ scheduler : scheduler ,
281
+ poolService : poolService ,
282
+ nbsFactory : nbsFactory ,
283
+ request : request ,
284
+ state : & protos.DeleteDiskTaskState {},
285
+ }
286
+
287
+ diskMeta := & resources.DiskMeta {
288
+ ZoneID : "zone" ,
289
+ DeleteTaskID : "toplevel_task_id" ,
290
+ }
291
+
292
+ if sync {
293
+ storage .On (
294
+ "GetDiskMeta" ,
295
+ ctx ,
296
+ "disk" ,
297
+ ).Return (diskMeta , nil ).Once ()
298
+ nbsClient .On ("Describe" , ctx , "disk" ).Return (nbs.DiskParams {
299
+ Kind : diskKind ,
300
+ BlocksCount : 100 * 256 , // 100 MiB
301
+ BlockSize : 4096 ,
302
+ }, nil )
303
+ }
304
+
305
+ storage .On (
306
+ "DeleteDisk" ,
307
+ ctx ,
308
+ "disk" ,
309
+ "toplevel_task_id" ,
310
+ mock .Anything ,
311
+ ).Return (diskMeta , nil ).Once ()
312
+ storage .On ("DiskDeleted" , ctx , "disk" , mock .Anything ).Return (nil )
313
+
314
+ if expectedEstimatedInflightDuration > 0 {
315
+ execCtx .On ("SetEstimatedInflightDuration" , expectedEstimatedInflightDuration )
316
+ }
317
+
318
+ nbsFactory .On ("GetClient" , ctx , "zone" ).Return (nbsClient , nil )
319
+ if sync {
320
+ nbsClient .On ("DeleteSync" , ctx , "disk" ).Return (nil )
321
+ } else {
322
+ nbsClient .On ("Delete" , ctx , "disk" ).Return (nil )
323
+ }
324
+
325
+ scheduler .On (
326
+ "ScheduleTask" ,
327
+ headers .SetIncomingIdempotencyKey (ctx , "toplevel_task_id_delete_disk_from_incremental" ),
328
+ "dataplane.DeleteDiskFromIncremental" ,
329
+ "" ,
330
+ mock .Anything ,
331
+ ).Return ("deleteTask" , nil )
332
+
333
+ scheduler .On ("WaitTask" , ctx , execCtx , "deleteTask" ).Return (nil , nil )
334
+
335
+ err := task .Run (ctx , execCtx )
336
+ mock .AssertExpectationsForObjects (t , storage , scheduler , nbsFactory , nbsClient , execCtx )
337
+ require .NoError (t , err )
338
+ }
339
+
340
+ func TestDeleteDiskTaskEstimatedInflightDurationForLocalDisks (t * testing.T ) {
341
+ testCases := []struct {
342
+ name string
343
+ sync bool
344
+ diskKind types.DiskKind
345
+ expectedEstimatedInflightDuration time.Duration
346
+ }{
347
+ {
348
+ name : "No estimate for any disks except local; Sync=false" ,
349
+ sync : false ,
350
+ diskKind : types .DiskKind_DISK_KIND_SSD ,
351
+ expectedEstimatedInflightDuration : 0 ,
352
+ },
353
+ {
354
+ name : "No estimate for any disks except local; Sync=true" ,
355
+ sync : true ,
356
+ diskKind : types .DiskKind_DISK_KIND_SSD ,
357
+ expectedEstimatedInflightDuration : 0 ,
358
+ },
359
+ {
360
+ name : "No estimate for Sync=false; DiskKind=ssd-local" ,
361
+ sync : false ,
362
+ diskKind : types .DiskKind_DISK_KIND_SSD_LOCAL ,
363
+ expectedEstimatedInflightDuration : 0 ,
364
+ },
365
+ {
366
+ name : "Estimate set for Sync=true; DiskKind=ssd-local" ,
367
+ sync : true ,
368
+ diskKind : types .DiskKind_DISK_KIND_SSD_LOCAL ,
369
+ expectedEstimatedInflightDuration : 1 * time .Second ,
370
+ },
371
+ {
372
+ name : "No estimate for Sync=false; DiskKind=hdd-local" ,
373
+ sync : false ,
374
+ diskKind : types .DiskKind_DISK_KIND_HDD_LOCAL ,
375
+ expectedEstimatedInflightDuration : 0 ,
376
+ },
377
+ {
378
+ name : "Estimate set for Sync=true; DiskKind=hdd-local" ,
379
+ sync : true ,
380
+ diskKind : types .DiskKind_DISK_KIND_HDD_LOCAL ,
381
+ expectedEstimatedInflightDuration : 10 * time .Second ,
382
+ },
383
+ }
384
+
385
+ for _ , testCase := range testCases {
386
+ t .Run (testCase .name , func (t * testing.T ) {
387
+ testDeleteDiskTaskEstimatedInflightDurationForLocalDisks (
388
+ t ,
389
+ testCase .sync ,
390
+ testCase .diskKind ,
391
+ testCase .expectedEstimatedInflightDuration ,
392
+ )
393
+ })
394
+ }
395
+ }
0 commit comments