From be68d06b406b225aa6e103c15c19472484570ce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Osipiuk?= Date: Fri, 7 Jun 2019 16:53:17 +0200 Subject: [PATCH] Add unit test case for OTHER error handling --- .../core/static_autoscaler_test.go | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/cluster-autoscaler/core/static_autoscaler_test.go b/cluster-autoscaler/core/static_autoscaler_test.go index c8513daa8e..2c798f2953 100644 --- a/cluster-autoscaler/core/static_autoscaler_test.go +++ b/cluster-autoscaler/core/static_autoscaler_test.go @@ -817,7 +817,7 @@ func TestStaticAutoscalerRunOncePodsWithPriorities(t *testing.T) { podDisruptionBudgetListerMock, daemonSetListerMock, onScaleUpMock, onScaleDownMock) } -func TestStaticAutoscalerOutOfResources(t *testing.T) { +func TestStaticAutoscalerInstaceCreationErrors(t *testing.T) { // setup provider := &mockprovider.CloudProvider{} @@ -904,6 +904,16 @@ func TestStaticAutoscalerOutOfResources(t *testing.T) { }, }, }, + { + "A6", + &cloudprovider.InstanceStatus{ + State: cloudprovider.InstanceCreating, + ErrorInfo: &cloudprovider.InstanceErrorInfo{ + ErrorClass: cloudprovider.OtherErrorClass, + ErrorCode: "OTHER", + }, + }, + }, }, nil).Twice() nodeGroupB.On("Exist").Return(true) @@ -944,14 +954,14 @@ func TestStaticAutoscalerOutOfResources(t *testing.T) { // check delete was called on correct nodes nodeGroupA.AssertCalled(t, "DeleteNodes", mock.MatchedBy( func(nodes []*apiv1.Node) bool { - if len(nodes) != 3 { + if len(nodes) != 4 { return false } names := make(map[string]bool) for _, node := range nodes { names[node.Spec.ProviderID] = true } - return names["A3"] && names["A4"] && names["A5"] + return names["A3"] && names["A4"] && names["A5"] && names["A6"] })) // TODO assert that scaleup was failed (separately for QUOTA and STOCKOUT) @@ -968,14 +978,14 @@ func TestStaticAutoscalerOutOfResources(t *testing.T) { // nodes should be deleted again nodeGroupA.AssertCalled(t, "DeleteNodes", mock.MatchedBy( func(nodes []*apiv1.Node) bool { - if len(nodes) != 3 { + if len(nodes) != 4 { return false } names := make(map[string]bool) for _, node := range nodes { names[node.Spec.ProviderID] = true } - return names["A3"] && names["A4"] && names["A5"] + return names["A3"] && names["A4"] && names["A5"] && names["A6"] })) // TODO assert that scaleup is not failed again @@ -1012,6 +1022,12 @@ func TestStaticAutoscalerOutOfResources(t *testing.T) { State: cloudprovider.InstanceDeleting, }, }, + { + "A6", + &cloudprovider.InstanceStatus{ + State: cloudprovider.InstanceDeleting, + }, + }, }, nil) clusterState.RefreshCloudProviderNodeInstancesCache()