-
Notifications
You must be signed in to change notification settings - Fork 38
[Disk Manager] Prepare cells storage for metrics #4728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 9 commits
ce6c4c3
c7a9482
613fcce
45c3f99
7d3a70f
32e1cce
07609d1
cd382e1
420c108
05f3b8c
a241e61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,27 @@ import ( | |
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| func matchClusterCapacities(t *testing.T, expected cells_storage.ClusterCapacity) interface{} { | ||
| return mock.MatchedBy(func(actual []cells_storage.ClusterCapacity) bool { | ||
| if len(actual) != 1 { | ||
| return false | ||
| } | ||
|
|
||
| got := actual[0] | ||
| if expected.FreeBytes != got.FreeBytes || | ||
| expected.TotalBytes != got.TotalBytes || | ||
| expected.CellID != got.CellID || expected.Kind != got.Kind || | ||
| expected.ZoneID != got.ZoneID || | ||
| time.Now().Sub(got.CreatedAt).Abs() >= time.Minute { | ||
|
||
| return false | ||
| } | ||
|
|
||
| return true | ||
| }) | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| func TestCollectClusterCapacityTask(t *testing.T) { | ||
| ctx := newContext() | ||
| execCtx := tasks_mocks.NewExecutionContextMock() | ||
|
|
@@ -56,41 +77,50 @@ func TestCollectClusterCapacityTask(t *testing.T) { | |
|
|
||
| storage.On("UpdateClusterCapacities", | ||
| mock.Anything, // ctx. | ||
| []cells_storage.ClusterCapacity{ | ||
| { | ||
| ZoneID: "zone-a", | ||
| CellID: "zone-a-cell1", | ||
| Kind: types.DiskKind_DISK_KIND_SSD, | ||
| FreeBytes: 1024, | ||
| TotalBytes: 2048, | ||
| matchClusterCapacities( | ||
| t, | ||
| []cells_storage.ClusterCapacity{ | ||
| { | ||
| ZoneID: "zone-a", | ||
| CellID: "zone-a-cell1", | ||
| Kind: types.DiskKind_DISK_KIND_SSD, | ||
| FreeBytes: 1024, | ||
| TotalBytes: 2048, | ||
| }, | ||
| }, | ||
| }, | ||
| ), | ||
| deleteOlderThanExpectation, | ||
| ).Return(nil).Once() | ||
| storage.On("UpdateClusterCapacities", | ||
| mock.Anything, // ctx. | ||
| []cells_storage.ClusterCapacity{ | ||
| { | ||
| ZoneID: "zone-a", | ||
| CellID: "zone-a", | ||
| Kind: types.DiskKind_DISK_KIND_SSD, | ||
| FreeBytes: 1024, | ||
| TotalBytes: 2048, | ||
| matchClusterCapacities( | ||
| t, | ||
| []cells_storage.ClusterCapacity{ | ||
| { | ||
| ZoneID: "zone-a", | ||
| CellID: "zone-a", | ||
| Kind: types.DiskKind_DISK_KIND_SSD, | ||
| FreeBytes: 1024, | ||
| TotalBytes: 2048, | ||
| }, | ||
| }, | ||
| }, | ||
| ), | ||
| deleteOlderThanExpectation, | ||
| ).Return(nil).Once() | ||
| storage.On("UpdateClusterCapacities", | ||
| mock.Anything, // ctx. | ||
| []cells_storage.ClusterCapacity{ | ||
| { | ||
| ZoneID: "zone-b", | ||
| CellID: "zone-b", | ||
| Kind: types.DiskKind_DISK_KIND_SSD, | ||
| FreeBytes: 1024, | ||
| TotalBytes: 2048, | ||
| matchClusterCapacities( | ||
| t, | ||
| []cells_storage.ClusterCapacity{ | ||
| { | ||
| ZoneID: "zone-b", | ||
| CellID: "zone-b", | ||
| Kind: types.DiskKind_DISK_KIND_SSD, | ||
| FreeBytes: 1024, | ||
| TotalBytes: 2048, | ||
| }, | ||
| }, | ||
| }, | ||
| ), | ||
| deleteOlderThanExpectation, | ||
| ).Return(nil).Once() | ||
|
|
||
|
|
@@ -163,15 +193,18 @@ func TestCollectClusterCapacityFailureNbsReturnsError(t *testing.T) { | |
| // Only the successful cell should be updated | ||
| storage.On("UpdateClusterCapacities", | ||
| mock.Anything, // ctx. | ||
| []cells_storage.ClusterCapacity{ | ||
| { | ||
| ZoneID: "zone-a", | ||
| CellID: "zone-a", | ||
| Kind: types.DiskKind_DISK_KIND_SSD, | ||
| FreeBytes: 1024, | ||
| TotalBytes: 2048, | ||
| matchClusterCapacities( | ||
| t, | ||
| []cells_storage.ClusterCapacity{ | ||
| { | ||
| ZoneID: "zone-a", | ||
| CellID: "zone-a", | ||
| Kind: types.DiskKind_DISK_KIND_SSD, | ||
| FreeBytes: 1024, | ||
| TotalBytes: 2048, | ||
| }, | ||
| }, | ||
| }, | ||
| ), | ||
| mock.Anything, // deleteOlderThan. | ||
| ).Return(nil).Once() | ||
|
|
||
|
|
@@ -232,28 +265,34 @@ func TestCollectClusterCapacityFailureStorageReturnsError(t *testing.T) { | |
|
|
||
| storage.On("UpdateClusterCapacities", | ||
| mock.Anything, // ctx. | ||
| []cells_storage.ClusterCapacity{ | ||
| { | ||
| ZoneID: "zone-a", | ||
| CellID: "zone-a", | ||
| Kind: types.DiskKind_DISK_KIND_SSD, | ||
| FreeBytes: 1024, | ||
| TotalBytes: 2048, | ||
| matchClusterCapacities( | ||
| t, | ||
| []cells_storage.ClusterCapacity{ | ||
| { | ||
| ZoneID: "zone-a", | ||
| CellID: "zone-a", | ||
| Kind: types.DiskKind_DISK_KIND_SSD, | ||
| FreeBytes: 1024, | ||
| TotalBytes: 2048, | ||
| }, | ||
| }, | ||
| }, | ||
| ), | ||
| mock.Anything, // deleteOlderThan. | ||
| ).Return(nil).Once() | ||
| storage.On("UpdateClusterCapacities", | ||
| mock.Anything, | ||
| []cells_storage.ClusterCapacity{ | ||
| { | ||
| ZoneID: "zone-a", | ||
| CellID: "zone-a-cell1", | ||
| Kind: types.DiskKind_DISK_KIND_SSD, | ||
| FreeBytes: 1024, | ||
| TotalBytes: 2048, | ||
| matchClusterCapacities( | ||
| t, | ||
| []cells_storage.ClusterCapacity{ | ||
| { | ||
| ZoneID: "zone-a", | ||
| CellID: "zone-a-cell1", | ||
| Kind: types.DiskKind_DISK_KIND_SSD, | ||
| FreeBytes: 1024, | ||
| TotalBytes: 2048, | ||
| }, | ||
| }, | ||
| }, | ||
| ), | ||
| mock.Anything, // deleteOlderThan. | ||
| ).Return(assert.AnError).Once() | ||
|
|
||
|
|
@@ -313,15 +352,18 @@ func TestCollectClusterCapacityOneCellHasAlreadyBeenProcessed(t *testing.T) { | |
|
|
||
| storage.On("UpdateClusterCapacities", | ||
| mock.Anything, // ctx. | ||
| []cells_storage.ClusterCapacity{ | ||
| { | ||
| ZoneID: "zone-a", | ||
| CellID: "zone-a", | ||
| Kind: types.DiskKind_DISK_KIND_SSD, | ||
| FreeBytes: 1024, | ||
| TotalBytes: 2048, | ||
| matchClusterCapacities( | ||
| t, | ||
| []cells_storage.ClusterCapacity{ | ||
| { | ||
| ZoneID: "zone-a", | ||
| CellID: "zone-a", | ||
| Kind: types.DiskKind_DISK_KIND_SSD, | ||
| FreeBytes: 1024, | ||
| TotalBytes: 2048, | ||
| }, | ||
| }, | ||
| }, | ||
| ), | ||
| mock.Anything, // deleteOlderThan. | ||
| ).Return(nil).Once() | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Теперь CreatedAt задаём в коде таски, нужно сверять время. Обычно в таких случаях мы просто подставляем
mock.Anything, но тут терялся бы смысл теста.В матчере сравниваем полученное время с time.Now(), т.к. такой же time.Now() выставляется в коде таски. Минута про запас