From c271037f5bc02169f0509e72fb86005b542a7005 Mon Sep 17 00:00:00 2001 From: "shaowei.wayne" Date: Sun, 14 Apr 2024 13:15:19 +0800 Subject: [PATCH] fix uint-tests to support parallel testings --- .../app/options/controllerbase_test.go | 5 + pkg/agent/evictionmanager/manager_test.go | 5 +- .../plugin/memory/numa_pressure_test.go | 68 ++++--- .../plugin/memory/rss_overuse_test.go | 28 ++- .../plugin/memory/system_pressure_test.go | 70 ++++--- .../plugin/rootfs/rootfs_pressure_test.go | 16 ++ .../evictionmanager/podkiller/killer_test.go | 18 +- pkg/agent/orm/manager_test.go | 4 + pkg/agent/orm/pod_resource_test.go | 1 + .../orm/topology/policy_best_effort_test.go | 3 + pkg/agent/orm/topology/policy_none_test.go | 6 + pkg/agent/orm/topology/policy_numeric_test.go | 2 + .../orm/topology/policy_restricted_test.go | 6 + .../topology/policy_single_numa_node_test.go | 6 + pkg/agent/orm/topology/policy_test.go | 9 + .../strategy/pressure_load_test.go | 177 +++++++++--------- .../strategy/pressure_suppression_test.go | 98 +++++----- .../cpu/dynamicpolicy/state/state_test.go | 70 +++---- .../cpu/dynamicpolicy/state/util_test.go | 2 + .../cpu/dynamicpolicy/util_test.go | 2 + .../calculator/cpu_assignment_test.go | 40 ++++ pkg/agent/qrm-plugins/cpu/util/util_test.go | 8 + .../io/handlers/iocost/iocost_linux_test.go | 18 ++ .../io/handlers/iocost/utils_test.go | 12 ++ .../io/staticpolicy/policy_test.go | 38 ++++ .../dynamicpolicy/oom/calculator_test.go | 3 + .../memory/dynamicpolicy/policy_test.go | 12 ++ .../dynamicpolicy/util_linux_amd64_test.go | 26 +++ .../memory/dynamicpolicy/util_test.go | 4 + .../kubelet/topology/topology_adapter_test.go | 11 ++ .../fetcher/plugin/endpoint_test.go | 1 + .../reporter/cnr/cnrreporter_test.go | 7 + .../resourcemanager/reporter/manager_test.go | 8 + .../sysadvisor/metacache/metacache_test.go | 10 + .../plugin/inference/inference_test.go | 13 ++ .../borwein/borwein_test.go | 70 ++++--- .../reporter/manager/resource/generic_test.go | 2 + .../qosaware/reporter/nodemetric_reporter.go | 26 +++ .../reporter/nodemetric_reporter_test.go | 3 + .../qosaware/resource/cpu/advisor_test.go | 3 + .../assembler_common_test.go | 3 + .../provisionassembler/assembler_test.go | 2 + .../resource/cpu/isolation/isolator_test.go | 44 ++--- .../headroompolicy/policy_canonical_test.go | 3 + .../policy_numa_exclusive_test.go | 3 + .../provisionpolicy/policy_canonical_test.go | 3 + .../provisionpolicy/policy_rama_test.go | 3 + .../resource/cpu/region/region_test.go | 3 + .../qosaware/resource/helper/memory_test.go | 3 + .../helper/modelctrl/borwein/borwein_test.go | 20 ++ .../qosaware/resource/memory/advisor_test.go | 3 + .../headroompolicy/policy_canonical_test.go | 3 + .../headroompolicy/policy_numa_aware_test.go | 3 + .../policy/policy_canonical_test.go | 3 + .../plugin/qosaware/server/cpu_server_test.go | 9 + .../qosaware/server/memory_server_test.go | 6 + pkg/agent/sysadvisor/test/sysadvisor_test.go | 3 + pkg/client/control/node_test.go | 9 + pkg/client/control/unstructured_test.go | 6 + pkg/client/control/vpa_test.go | 6 + pkg/client/control/vparec_test.go | 6 + pkg/controller/kcc/cnc_test.go | 3 + pkg/controller/kcc/kcc_test.go | 6 + pkg/controller/kcc/kcct_test.go | 17 ++ pkg/controller/kcc/util/kcct_test.go | 5 + .../agent-healthz/healthz_controller_test.go | 7 +- pkg/controller/lifecycle/cnc_test.go | 6 + pkg/controller/lifecycle/cnr_test.go | 6 + pkg/controller/monitor/cnr_indicator_test.go | 10 + pkg/controller/monitor/cnr_test.go | 6 + .../overcommit/node/matcher/matcher_test.go | 15 ++ pkg/controller/overcommit/node/node_test.go | 5 + pkg/controller/spd/spd_baseline_test.go | 3 + pkg/controller/spd/spd_test.go | 2 + pkg/controller/tide/tide_test.go | 10 + .../recommenders/avg_load_to_cpu_test.go | 3 + pkg/controller/vpa/recommend_test.go | 3 + pkg/controller/vpa/util/api_test.go | 17 +- pkg/controller/vpa/util/resource_test.go | 6 + pkg/controller/vpa/vpa_test.go | 9 + pkg/controller/vpa/vparec_test.go | 6 + pkg/custom-metric/store/data/cache_test.go | 2 + .../agent/metric/metric_expire_test.go | 2 + .../malachite/client/client_pod_test.go | 2 + pkg/metaserver/agent/pod/pod_test.go | 26 +-- .../external/cgroupid/manager_linux_test.go | 10 + pkg/metaserver/kcc/config_test.go | 2 + pkg/metaserver/kcc/manager_test.go | 10 + pkg/metaserver/spd/fetcher_test.go | 5 +- pkg/metaserver/spd/manager_test.go | 17 +- pkg/metaserver/spd/util_test.go | 2 + pkg/util/bitmask/bitmask_test.go | 32 ++++ pkg/util/cgroup/manager/v1/fs_linux_test.go | 5 + pkg/util/cgroup/manager/v2/fs_linux_test.go | 64 +++++++ pkg/util/cnr_test.go | 12 ++ .../credential/authorization/dynamic_test.go | 2 + .../credential/authorization/insecure_test.go | 2 + .../credential/authorization/static_test.go | 2 + pkg/util/credential/basic_test.go | 6 + pkg/util/credential/insecure_test.go | 4 + pkg/util/general/flags_test.go | 5 + pkg/util/general/list_test.go | 4 + pkg/util/general/string_test.go | 4 + pkg/util/general/window_test.go | 7 + pkg/util/kcct_test.go | 41 ++++ pkg/util/native/pod_sorter_test.go | 4 + pkg/util/native/pods_test.go | 20 ++ pkg/util/native/qos_resources_test.go | 2 + pkg/util/native/resources_test.go | 10 + pkg/util/qos/net_enhancement_test.go | 3 + pkg/util/qos/oom_priority_test.go | 2 + .../service_single_port_sd_test.go | 2 + pkg/util/spd_baseline_test.go | 16 ++ pkg/util/spd_test.go | 8 + pkg/util/vpa_test.go | 10 + pkg/webhook/mutating/node/node_test.go | 3 + pkg/webhook/mutating/pod/pod_test.go | 3 + 117 files changed, 1201 insertions(+), 350 deletions(-) diff --git a/cmd/katalyst-controller/app/options/controllerbase_test.go b/cmd/katalyst-controller/app/options/controllerbase_test.go index 7a2912244..e54db0463 100644 --- a/cmd/katalyst-controller/app/options/controllerbase_test.go +++ b/cmd/katalyst-controller/app/options/controllerbase_test.go @@ -25,6 +25,8 @@ import ( ) func TestWorkloadProfilingOptions(t *testing.T) { + t.Parallel() + workload := &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: "pod", @@ -200,7 +202,10 @@ func TestWorkloadProfilingOptions(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + f, ok, err := tt.options.getWorkloadEnableFunc() assert.NoError(t, err) if ok { diff --git a/pkg/agent/evictionmanager/manager_test.go b/pkg/agent/evictionmanager/manager_test.go index 008caa5a4..b9c4accd4 100644 --- a/pkg/agent/evictionmanager/manager_test.go +++ b/pkg/agent/evictionmanager/manager_test.go @@ -237,7 +237,6 @@ func makeEvictionManager(t *testing.T) *EvictionManger { func TestEvictionManger_collectEvictionResult(t *testing.T) { t.Parallel() - mgr := makeEvictionManager(t) tests := []struct { name string dryrun []string @@ -299,7 +298,11 @@ func TestEvictionManger_collectEvictionResult(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + mgr := makeEvictionManager(t) mgr.conf.GetDynamicConfiguration().DryRun = tt.dryrun collector, _ := mgr.collectEvictionResult(pods) diff --git a/pkg/agent/evictionmanager/plugin/memory/numa_pressure_test.go b/pkg/agent/evictionmanager/plugin/memory/numa_pressure_test.go index 56866530e..49e87f770 100644 --- a/pkg/agent/evictionmanager/plugin/memory/numa_pressure_test.go +++ b/pkg/agent/evictionmanager/plugin/memory/numa_pressure_test.go @@ -205,26 +205,24 @@ func TestNumaMemoryPressurePlugin_ThresholdMet(t *testing.T) { } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - now := time.Now() - for numaID, numaFree := range tt.numaFree { - fakeMetricsFetcher.SetNumaMetric(numaID, consts.MetricMemFreeNuma, utilMetric.MetricData{Value: numaFree, Time: &now}) - } - - metResp, err := plugin.ThresholdMet(context.TODO()) - assert.NoError(t, err) - assert.NotNil(t, metResp) - assert.Equal(t, tt.wantMetType, metResp.MetType) - assert.Equal(t, tt.wantEvictionScope, metResp.EvictionScope) - if tt.wantCondition != nil && metResp.Condition != nil { - assert.Equal(t, *(tt.wantCondition), *(metResp.Condition)) - } else { - assert.Equal(t, tt.wantCondition, metResp.Condition) - } - - assert.Equal(t, tt.wantIsUnderNumaPressure, plugin.isUnderNumaPressure) - assert.Equal(t, tt.wantNumaAction, plugin.numaActionMap) - }) + now := time.Now() + for numaID, numaFree := range tt.numaFree { + fakeMetricsFetcher.SetNumaMetric(numaID, consts.MetricMemFreeNuma, utilMetric.MetricData{Value: numaFree, Time: &now}) + } + + metResp, err := plugin.ThresholdMet(context.TODO()) + assert.NoError(t, err) + assert.NotNil(t, metResp) + assert.Equal(t, tt.wantMetType, metResp.MetType) + assert.Equal(t, tt.wantEvictionScope, metResp.EvictionScope) + if tt.wantCondition != nil && metResp.Condition != nil { + assert.Equal(t, *(tt.wantCondition), *(metResp.Condition)) + } else { + assert.Equal(t, tt.wantCondition, metResp.Condition) + } + + assert.Equal(t, tt.wantIsUnderNumaPressure, plugin.isUnderNumaPressure) + assert.Equal(t, tt.wantNumaAction, plugin.numaActionMap) } } @@ -369,22 +367,20 @@ func TestNumaMemoryPressurePlugin_GetTopEvictionPods(t *testing.T) { } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - plugin.isUnderNumaPressure = tt.isUnderNumaPressure - plugin.numaActionMap = tt.numaAction - resp, err := plugin.GetTopEvictionPods(context.TODO(), &pluginapi.GetTopEvictionPodsRequest{ - ActivePods: bePods, - TopN: 1, - EvictionScope: EvictionScopeNumaMemory, - }) - assert.NoError(t, err) - assert.NotNil(t, resp) - - targetPodSet := sets.String{} - for _, pod := range resp.TargetPods { - targetPodSet.Insert(pod.Name) - } - assert.Equal(t, targetPodSet, tt.wantEvictPodSet) + plugin.isUnderNumaPressure = tt.isUnderNumaPressure + plugin.numaActionMap = tt.numaAction + resp, err := plugin.GetTopEvictionPods(context.TODO(), &pluginapi.GetTopEvictionPodsRequest{ + ActivePods: bePods, + TopN: 1, + EvictionScope: EvictionScopeNumaMemory, }) + assert.NoError(t, err) + assert.NotNil(t, resp) + + targetPodSet := sets.String{} + for _, pod := range resp.TargetPods { + targetPodSet.Insert(pod.Name) + } + assert.Equal(t, targetPodSet, tt.wantEvictPodSet) } } diff --git a/pkg/agent/evictionmanager/plugin/memory/rss_overuse_test.go b/pkg/agent/evictionmanager/plugin/memory/rss_overuse_test.go index 78e2e5c42..8d5ae1232 100644 --- a/pkg/agent/evictionmanager/plugin/memory/rss_overuse_test.go +++ b/pkg/agent/evictionmanager/plugin/memory/rss_overuse_test.go @@ -355,23 +355,21 @@ func TestRssOveruseEvictionPlugin_GetEvictPods(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - plugin.dynamicConfig.GetDynamicConfiguration().EnableRSSOveruseEviction = tt.enableRssOveruse - plugin.dynamicConfig.GetDynamicConfiguration().RSSOveruseRateThreshold = tt.defaultRssOveruseThreshold - plugin.evictionConfig.RSSOveruseEvictionFilter = tt.podFilter + plugin.dynamicConfig.GetDynamicConfiguration().EnableRSSOveruseEviction = tt.enableRssOveruse + plugin.dynamicConfig.GetDynamicConfiguration().RSSOveruseRateThreshold = tt.defaultRssOveruseThreshold + plugin.evictionConfig.RSSOveruseEvictionFilter = tt.podFilter - evictPods, err2 := plugin.GetEvictPods(context.TODO(), &pluginapi.GetEvictPodsRequest{ - ActivePods: pods, - }) - assert.NoError(t, err2) - assert.Nil(t, evictPods.Condition) + evictPods, err2 := plugin.GetEvictPods(context.TODO(), &pluginapi.GetEvictPodsRequest{ + ActivePods: pods, + }) + assert.NoError(t, err2) + assert.Nil(t, evictPods.Condition) - gotPods := sets.String{} - for i := range evictPods.EvictPods { - gotPods.Insert(evictPods.EvictPods[i].Pod.Name) - } + gotPods := sets.String{} + for i := range evictPods.EvictPods { + gotPods.Insert(evictPods.EvictPods[i].Pod.Name) + } - assert.Equal(t, tt.wantedResult, gotPods) - }) + assert.Equal(t, tt.wantedResult, gotPods) } } diff --git a/pkg/agent/evictionmanager/plugin/memory/system_pressure_test.go b/pkg/agent/evictionmanager/plugin/memory/system_pressure_test.go index 2a0649331..8702a7964 100644 --- a/pkg/agent/evictionmanager/plugin/memory/system_pressure_test.go +++ b/pkg/agent/evictionmanager/plugin/memory/system_pressure_test.go @@ -273,26 +273,24 @@ func TestSystemPressureEvictionPlugin_ThresholdMet(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - now := start.Add(time.Duration(tt.round) * plugin.syncPeriod) - fakeMetricsFetcher.SetNodeMetric(consts.MetricMemFreeSystem, utilMetric.MetricData{Value: tt.systemFree, Time: &now}) - fakeMetricsFetcher.SetNodeMetric(consts.MetricMemKswapdstealSystem, utilMetric.MetricData{Value: tt.systemKswapSteal, Time: &now}) - - plugin.detectSystemPressures(context.TODO()) - metResp, err := plugin.ThresholdMet(context.TODO()) - assert.NoError(t, err) - assert.NotNil(t, metResp) - assert.Equal(t, tt.wantMetType, metResp.MetType) - assert.Equal(t, tt.wantEvictionScope, metResp.EvictionScope) - if tt.wantCondition != nil && metResp.Condition != nil { - assert.Equal(t, *(tt.wantCondition), *(metResp.Condition)) - } else { - assert.Equal(t, tt.wantCondition, metResp.Condition) - } - - assert.Equal(t, tt.wantIsUnderSystemPressure, plugin.isUnderSystemPressure) - assert.Equal(t, tt.wantSystemAction, plugin.systemAction) - }) + now := start.Add(time.Duration(tt.round) * plugin.syncPeriod) + fakeMetricsFetcher.SetNodeMetric(consts.MetricMemFreeSystem, utilMetric.MetricData{Value: tt.systemFree, Time: &now}) + fakeMetricsFetcher.SetNodeMetric(consts.MetricMemKswapdstealSystem, utilMetric.MetricData{Value: tt.systemKswapSteal, Time: &now}) + + plugin.detectSystemPressures(context.TODO()) + metResp, err := plugin.ThresholdMet(context.TODO()) + assert.NoError(t, err) + assert.NotNil(t, metResp) + assert.Equal(t, tt.wantMetType, metResp.MetType) + assert.Equal(t, tt.wantEvictionScope, metResp.EvictionScope) + if tt.wantCondition != nil && metResp.Condition != nil { + assert.Equal(t, *(tt.wantCondition), *(metResp.Condition)) + } else { + assert.Equal(t, tt.wantCondition, metResp.Condition) + } + + assert.Equal(t, tt.wantIsUnderSystemPressure, plugin.isUnderSystemPressure) + assert.Equal(t, tt.wantSystemAction, plugin.systemAction) } } @@ -391,23 +389,21 @@ func TestSystemPressureEvictionPlugin_GetTopEvictionPods(t *testing.T) { } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - plugin.isUnderSystemPressure = tt.isUnderSystemPressure - plugin.systemAction = tt.systemAction - plugin.lastEvictionTime = tt.lastEvictionTime - resp, err := plugin.GetTopEvictionPods(context.TODO(), &pluginapi.GetTopEvictionPodsRequest{ - ActivePods: bePods, - TopN: 1, - EvictionScope: EvictionScopeSystemMemory, - }) - assert.NoError(t, err) - assert.NotNil(t, resp) - - targetPodSet := sets.String{} - for _, pod := range resp.TargetPods { - targetPodSet.Insert(pod.Name) - } - assert.Equal(t, tt.wantEvictPodSet, targetPodSet) + plugin.isUnderSystemPressure = tt.isUnderSystemPressure + plugin.systemAction = tt.systemAction + plugin.lastEvictionTime = tt.lastEvictionTime + resp, err := plugin.GetTopEvictionPods(context.TODO(), &pluginapi.GetTopEvictionPodsRequest{ + ActivePods: bePods, + TopN: 1, + EvictionScope: EvictionScopeSystemMemory, }) + assert.NoError(t, err) + assert.NotNil(t, resp) + + targetPodSet := sets.String{} + for _, pod := range resp.TargetPods { + targetPodSet.Insert(pod.Name) + } + assert.Equal(t, tt.wantEvictPodSet, targetPodSet) } } diff --git a/pkg/agent/evictionmanager/plugin/rootfs/rootfs_pressure_test.go b/pkg/agent/evictionmanager/plugin/rootfs/rootfs_pressure_test.go index b95cfffcf..1f8e2dfaa 100644 --- a/pkg/agent/evictionmanager/plugin/rootfs/rootfs_pressure_test.go +++ b/pkg/agent/evictionmanager/plugin/rootfs/rootfs_pressure_test.go @@ -74,6 +74,7 @@ func createRootfsPressureEvictionPlugin(tc *testConf, emitter metrics.MetricEmit } func TestPodRootfsPressureEvictionPlugin_ThresholdMetNoMetricDataNoConf(t *testing.T) { + t.Parallel() emitter := metrics.DummyMetrics{} fakeFetcher := metric.NewFakeMetricsFetcher(emitter).(*metric.FakeMetricsFetcher) tc := &testConf{} @@ -84,6 +85,7 @@ func TestPodRootfsPressureEvictionPlugin_ThresholdMetNoMetricDataNoConf(t *testi } func TestPodRootfsPressureEvictionPlugin_ThresholdMetNoMetricData(t *testing.T) { + t.Parallel() emitter := metrics.DummyMetrics{} fakeFetcher := metric.NewFakeMetricsFetcher(emitter).(*metric.FakeMetricsFetcher) tc := &testConf{ @@ -97,6 +99,7 @@ func TestPodRootfsPressureEvictionPlugin_ThresholdMetNoMetricData(t *testing.T) } func TestPodRootfsPressureEvictionPlugin_ThresholdMetNotMet(t *testing.T) { + t.Parallel() emitter := metrics.DummyMetrics{} fakeFetcher := metric.NewFakeMetricsFetcher(emitter).(*metric.FakeMetricsFetcher) // create metric data without time. @@ -129,6 +132,7 @@ func TestPodRootfsPressureEvictionPlugin_ThresholdMetNotMet(t *testing.T) { } func TestPodRootfsPressureEvictionPlugin_ThresholdMetUsedMet(t *testing.T) { + t.Parallel() emitter := metrics.DummyMetrics{} fakeFetcher := metric.NewFakeMetricsFetcher(emitter).(*metric.FakeMetricsFetcher) // create metric data without time. @@ -161,6 +165,7 @@ func TestPodRootfsPressureEvictionPlugin_ThresholdMetUsedMet(t *testing.T) { } func TestPodRootfsPressureEvictionPlugin_ThresholdMetInodesMet(t *testing.T) { + t.Parallel() emitter := metrics.DummyMetrics{} fakeFetcher := metric.NewFakeMetricsFetcher(emitter).(*metric.FakeMetricsFetcher) // create metric data without time. @@ -193,6 +198,7 @@ func TestPodRootfsPressureEvictionPlugin_ThresholdMetInodesMet(t *testing.T) { } func TestPodRootfsPressureEvictionPlugin_ThresholdMet(t *testing.T) { + t.Parallel() emitter := metrics.DummyMetrics{} fakeFetcher := metric.NewFakeMetricsFetcher(emitter).(*metric.FakeMetricsFetcher) // create metric data without time. @@ -225,6 +231,7 @@ func TestPodRootfsPressureEvictionPlugin_ThresholdMet(t *testing.T) { } func TestPodRootfsPressureEvictionPlugin_ThresholdMetMetricDataExpire(t *testing.T) { + t.Parallel() metricTime := time.Now().Add(-65 * time.Second) emitter := metrics.DummyMetrics{} @@ -287,6 +294,7 @@ func makeGetTopNRequest() *pluginapi.GetTopEvictionPodsRequest { } func TestPodRootfsPressureEvictionPlugin_GetTopEvictionPodsNotMet(t *testing.T) { + t.Parallel() emitter := metrics.DummyMetrics{} fakeFetcher := metric.NewFakeMetricsFetcher(emitter).(*metric.FakeMetricsFetcher) // create metric data without time. @@ -320,6 +328,7 @@ func TestPodRootfsPressureEvictionPlugin_GetTopEvictionPodsNotMet(t *testing.T) } func TestPodRootfsPressureEvictionPlugin_GetTopEvictionPodsMet(t *testing.T) { + t.Parallel() emitter := metrics.DummyMetrics{} fakeFetcher := metric.NewFakeMetricsFetcher(emitter).(*metric.FakeMetricsFetcher) // create metric data without time. @@ -361,6 +370,7 @@ func TestPodRootfsPressureEvictionPlugin_GetTopEvictionPodsMet(t *testing.T) { } func TestPodRootfsPressureEvictionPlugin_GetTopEvictionPodsUsedMet(t *testing.T) { + t.Parallel() emitter := metrics.DummyMetrics{} fakeFetcher := metric.NewFakeMetricsFetcher(emitter).(*metric.FakeMetricsFetcher) // create metric data without time. @@ -402,6 +412,7 @@ func TestPodRootfsPressureEvictionPlugin_GetTopEvictionPodsUsedMet(t *testing.T) } func TestPodRootfsPressureEvictionPlugin_GetTopEvictionPodsInodesMet(t *testing.T) { + t.Parallel() emitter := metrics.DummyMetrics{} fakeFetcher := metric.NewFakeMetricsFetcher(emitter).(*metric.FakeMetricsFetcher) // create metric data without time. @@ -443,6 +454,7 @@ func TestPodRootfsPressureEvictionPlugin_GetTopEvictionPodsInodesMet(t *testing. } func TestPodRootfsPressureEvictionPlugin_GetTopEvictionPodsUsedMetProtection(t *testing.T) { + t.Parallel() emitter := metrics.DummyMetrics{} fakeFetcher := metric.NewFakeMetricsFetcher(emitter).(*metric.FakeMetricsFetcher) // create metric data without time. @@ -549,6 +561,7 @@ func TestPodRootfsPressureEvictionPlugin_GetTopEvictionPodsUsedMetProtection(t * } func TestPodRootfsPressureEvictionPlugin_GetTopEvictionPodsInodesMetProtection(t *testing.T) { + t.Parallel() emitter := metrics.DummyMetrics{} fakeFetcher := metric.NewFakeMetricsFetcher(emitter).(*metric.FakeMetricsFetcher) // create metric data without time. @@ -653,6 +666,7 @@ func TestPodRootfsPressureEvictionPlugin_GetTopEvictionPodsInodesMetProtection(t } func TestPodRootfsPressureEvictionPlugin_GetTopEvictionPodsMetReclaimedPriority(t *testing.T) { + t.Parallel() emitter := metrics.DummyMetrics{} fakeFetcher := metric.NewFakeMetricsFetcher(emitter).(*metric.FakeMetricsFetcher) // create metric data without time. @@ -809,6 +823,7 @@ func TestPodRootfsPressureEvictionPlugin_GetTopEvictionPodsMetReclaimedPriority( } func TestPodRootfsPressureEvictionPlugin_GetTopEvictionPodsInodesMetReclaimedPriority(t *testing.T) { + t.Parallel() emitter := metrics.DummyMetrics{} fakeFetcher := metric.NewFakeMetricsFetcher(emitter).(*metric.FakeMetricsFetcher) // create metric data without time. @@ -965,6 +980,7 @@ func TestPodRootfsPressureEvictionPlugin_GetTopEvictionPodsInodesMetReclaimedPri } func TestPodRootfsPressureEvictionPlugin_GetTopEvictionPodsMetExpire(t *testing.T) { + t.Parallel() metricTime := time.Now().Add(-65 * time.Second) emitter := metrics.DummyMetrics{} diff --git a/pkg/agent/evictionmanager/podkiller/killer_test.go b/pkg/agent/evictionmanager/podkiller/killer_test.go index 8200f1f27..c734db950 100644 --- a/pkg/agent/evictionmanager/podkiller/killer_test.go +++ b/pkg/agent/evictionmanager/podkiller/killer_test.go @@ -166,15 +166,13 @@ func TestContainerKiller_Evict(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - fakeRuntimeService.Called = make([]string, 0) - evictErr := containerKiller.Evict(context.TODO(), tt.pod, 0, "test", "test") - if tt.wantStopFailed { - require.Error(t, evictErr) - } else { - require.NoError(t, evictErr) - require.Equal(t, tt.wantKillContainerCount, len(fakeRuntimeService.GetCalls())) - } - }) + fakeRuntimeService.Called = make([]string, 0) + evictErr := containerKiller.Evict(context.TODO(), tt.pod, 0, "test", "test") + if tt.wantStopFailed { + require.Error(t, evictErr) + } else { + require.NoError(t, evictErr) + require.Equal(t, tt.wantKillContainerCount, len(fakeRuntimeService.GetCalls())) + } } } diff --git a/pkg/agent/orm/manager_test.go b/pkg/agent/orm/manager_test.go index 5c8986b84..8cc3f73e7 100644 --- a/pkg/agent/orm/manager_test.go +++ b/pkg/agent/orm/manager_test.go @@ -268,7 +268,9 @@ func TestIsSkippedContainer(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.Name, func(t *testing.T) { + t.Parallel() res := isSkippedContainer(tc.Pod, tc.Container) assert.Equal(t, res, tc.Expected) }) @@ -323,7 +325,9 @@ func TestGetMappedResourceName(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.Name, func(t *testing.T) { + t.Parallel() r, err := m.getMappedResourceName(tc.resourceName, tc.requests) if tc.expectErr { assert.NotNil(t, err) diff --git a/pkg/agent/orm/pod_resource_test.go b/pkg/agent/orm/pod_resource_test.go index 6096a66bd..7ed3b591f 100644 --- a/pkg/agent/orm/pod_resource_test.go +++ b/pkg/agent/orm/pod_resource_test.go @@ -78,6 +78,7 @@ func TestPodResources(t *testing.T) { } func TestCheckpointMarshal(t *testing.T) { + t.Parallel() /* ---- use allocationInfo.Marshal ----- */ podResources := newPodResourcesChk() podResources.resources = map[string]ContainerResources{ diff --git a/pkg/agent/orm/topology/policy_best_effort_test.go b/pkg/agent/orm/topology/policy_best_effort_test.go index a78fa7b55..4016afa54 100644 --- a/pkg/agent/orm/topology/policy_best_effort_test.go +++ b/pkg/agent/orm/topology/policy_best_effort_test.go @@ -21,6 +21,7 @@ import ( ) func TestPolicyBestEffortCanAdmitPodResult(t *testing.T) { + t.Parallel() tcases := []struct { name string hint TopologyHint @@ -50,6 +51,8 @@ func TestPolicyBestEffortCanAdmitPodResult(t *testing.T) { } func TestPolicyBestEffortMerge(t *testing.T) { + t.Parallel() + numaNodes := []int{0, 1, 2, 3} policy := NewBestEffortPolicy(numaNodes) diff --git a/pkg/agent/orm/topology/policy_none_test.go b/pkg/agent/orm/topology/policy_none_test.go index 3e1a36324..174401c0a 100644 --- a/pkg/agent/orm/topology/policy_none_test.go +++ b/pkg/agent/orm/topology/policy_none_test.go @@ -21,6 +21,8 @@ import ( ) func TestPolicyNoneName(t *testing.T) { + t.Parallel() + tcases := []struct { name string expected string @@ -39,6 +41,8 @@ func TestPolicyNoneName(t *testing.T) { } func TestPolicyNoneCanAdmitPodResult(t *testing.T) { + t.Parallel() + tcases := []struct { name string hint TopologyHint @@ -67,6 +71,8 @@ func TestPolicyNoneCanAdmitPodResult(t *testing.T) { } func TestPolicyNoneMerge(t *testing.T) { + t.Parallel() + tcases := []struct { name string providersHints []map[string][]TopologyHint diff --git a/pkg/agent/orm/topology/policy_numeric_test.go b/pkg/agent/orm/topology/policy_numeric_test.go index 0990a71a4..72642ba25 100644 --- a/pkg/agent/orm/topology/policy_numeric_test.go +++ b/pkg/agent/orm/topology/policy_numeric_test.go @@ -19,6 +19,8 @@ package topology import "testing" func TestPolicyNumericMerge(t *testing.T) { + t.Parallel() + policy := NewNumericPolicy(defaultAlignResourceNames) tcases := []policyMergeTestCase{ diff --git a/pkg/agent/orm/topology/policy_restricted_test.go b/pkg/agent/orm/topology/policy_restricted_test.go index e9d3730d1..a8b0d994d 100644 --- a/pkg/agent/orm/topology/policy_restricted_test.go +++ b/pkg/agent/orm/topology/policy_restricted_test.go @@ -21,6 +21,8 @@ import ( ) func TestPolicyRestrictedName(t *testing.T) { + t.Parallel() + tcases := []struct { name string expected string @@ -39,6 +41,8 @@ func TestPolicyRestrictedName(t *testing.T) { } func TestPolicyRestrictedCanAdmitPodResult(t *testing.T) { + t.Parallel() + tcases := []struct { name string hint TopologyHint @@ -68,6 +72,8 @@ func TestPolicyRestrictedCanAdmitPodResult(t *testing.T) { } func TestPolicyRestrictedMerge(t *testing.T) { + t.Parallel() + numaNodes := []int{0, 1, 2, 3} policy := NewRestrictedPolicy(numaNodes) diff --git a/pkg/agent/orm/topology/policy_single_numa_node_test.go b/pkg/agent/orm/topology/policy_single_numa_node_test.go index 3be0b4122..52baa3dd8 100644 --- a/pkg/agent/orm/topology/policy_single_numa_node_test.go +++ b/pkg/agent/orm/topology/policy_single_numa_node_test.go @@ -22,6 +22,8 @@ import ( ) func TestPolicySingleNumaNodeCanAdmitPodResult(t *testing.T) { + t.Parallel() + tcases := []struct { name string hint TopologyHint @@ -46,6 +48,8 @@ func TestPolicySingleNumaNodeCanAdmitPodResult(t *testing.T) { } func TestPolicySingleNumaNodeFilterHints(t *testing.T) { + t.Parallel() + tcases := []struct { name string allResources [][]TopologyHint @@ -156,6 +160,8 @@ func TestPolicySingleNumaNodeFilterHints(t *testing.T) { } func TestPolicySingleNumaNodeMerge(t *testing.T) { + t.Parallel() + numaNodes := []int{0, 1, 2, 3} policy := NewSingleNumaNodePolicy(numaNodes) diff --git a/pkg/agent/orm/topology/policy_test.go b/pkg/agent/orm/topology/policy_test.go index 26255fe74..b29df5cd4 100644 --- a/pkg/agent/orm/topology/policy_test.go +++ b/pkg/agent/orm/topology/policy_test.go @@ -1315,6 +1315,8 @@ func testPolicyMerge(policy Policy, tcases []policyMergeTestCase, t *testing.T) } func TestMaxOfMinAffinityCounts(t *testing.T) { + t.Parallel() + tcases := []struct { hints [][]TopologyHint expected int @@ -1384,7 +1386,9 @@ func TestMaxOfMinAffinityCounts(t *testing.T) { } for _, tc := range tcases { + tc := tc t.Run("", func(t *testing.T) { + t.Parallel() result := maxOfMinAffinityCounts(tc.hints) if result != tc.expected { t.Errorf("Expected result to be %v, got %v", tc.expected, result) @@ -1394,6 +1398,8 @@ func TestMaxOfMinAffinityCounts(t *testing.T) { } func TestCompareHints(t *testing.T) { + t.Parallel() + tcases := []struct { description string bestNonPreferredAffinityCount int @@ -1579,7 +1585,10 @@ func TestCompareHints(t *testing.T) { } for _, tc := range tcases { + tc := tc t.Run(tc.description, func(t *testing.T) { + t.Parallel() + result := compareHints(tc.bestNonPreferredAffinityCount, tc.current, tc.candidate) if result != tc.current && result != tc.candidate { t.Errorf("Expected result to be either 'current' or 'candidate' hint") diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_load_test.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_load_test.go index a364379e0..225e5bb45 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_load_test.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_load_test.go @@ -365,47 +365,45 @@ func TestThresholdMet(t *testing.T) { } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - now := time.Now() + now := time.Now() - stateImpl, err := makeState(cpuTopology) - as.Nil(err) + stateImpl, err := makeState(cpuTopology) + as.Nil(err) - fakeMetricsFetcher := metric.NewFakeMetricsFetcher(metrics.DummyMetrics{}).(*metric.FakeMetricsFetcher) - assert.NotNil(t, fakeMetricsFetcher) + fakeMetricsFetcher := metric.NewFakeMetricsFetcher(metrics.DummyMetrics{}).(*metric.FakeMetricsFetcher) + assert.NotNil(t, fakeMetricsFetcher) - for entryName, entries := range tt.podEntries { - for subEntryName, entry := range entries { - stateImpl.SetAllocationInfo(entryName, subEntryName, entry) - - if entries.IsPoolEntry() { - continue - } + for entryName, entries := range tt.podEntries { + for subEntryName, entry := range entries { + stateImpl.SetAllocationInfo(entryName, subEntryName, entry) - curLoad, found := tt.loads[entryName][subEntryName] - as.True(found) - fakeMetricsFetcher.SetContainerMetric(entryName, subEntryName, consts.MetricLoad1MinContainer, utilmetric.MetricData{Value: curLoad, Time: &now}) + if entries.IsPoolEntry() { + continue } + + curLoad, found := tt.loads[entryName][subEntryName] + as.True(found) + fakeMetricsFetcher.SetContainerMetric(entryName, subEntryName, consts.MetricLoad1MinContainer, utilmetric.MetricData{Value: curLoad, Time: &now}) } + } - plugin.(*CPUPressureLoadEviction).state = stateImpl + plugin.(*CPUPressureLoadEviction).state = stateImpl - plugin.(*CPUPressureLoadEviction).metaServer.MetricsFetcher = fakeMetricsFetcher + plugin.(*CPUPressureLoadEviction).metaServer.MetricsFetcher = fakeMetricsFetcher - plugin.(*CPUPressureLoadEviction).collectMetrics(context.Background()) + plugin.(*CPUPressureLoadEviction).collectMetrics(context.Background()) - metResp, err := plugin.ThresholdMet(context.Background(), &evictionpluginapi.Empty{}) - as.Nil(err) - as.NotNil(t, metResp) - - as.Equal(tt.wantMetType, metResp.MetType) - as.Equal(tt.wantEvictionScope, metResp.EvictionScope) - if tt.wantCondition != nil && metResp.Condition != nil { - as.Equal(*(tt.wantCondition), *(metResp.Condition)) - } else { - as.Equal(tt.wantCondition, metResp.Condition) - } - }) + metResp, err := plugin.ThresholdMet(context.Background(), &evictionpluginapi.Empty{}) + as.Nil(err) + as.NotNil(t, metResp) + + as.Equal(tt.wantMetType, metResp.MetType) + as.Equal(tt.wantEvictionScope, metResp.EvictionScope) + if tt.wantCondition != nil && metResp.Condition != nil { + as.Equal(*(tt.wantCondition), *(metResp.Condition)) + } else { + as.Equal(tt.wantCondition, metResp.Condition) + } } } @@ -730,81 +728,79 @@ func TestGetTopEvictionPods(t *testing.T) { } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - now := time.Now() + now := time.Now() - stateImpl, err := makeState(cpuTopology) - as.Nil(err) + stateImpl, err := makeState(cpuTopology) + as.Nil(err) - fakeMetricsFetcher := metric.NewFakeMetricsFetcher(metrics.DummyMetrics{}).(*metric.FakeMetricsFetcher) - assert.NotNil(t, fakeMetricsFetcher) + fakeMetricsFetcher := metric.NewFakeMetricsFetcher(metrics.DummyMetrics{}).(*metric.FakeMetricsFetcher) + assert.NotNil(t, fakeMetricsFetcher) - pods := make([]*v1.Pod, 0, len(tt.podEntries)) - candidatePods := make([]*v1.Pod, 0, len(tt.podEntries)) + pods := make([]*v1.Pod, 0, len(tt.podEntries)) + candidatePods := make([]*v1.Pod, 0, len(tt.podEntries)) - for entryName, entries := range tt.podEntries { - for subEntryName, entry := range entries { - stateImpl.SetAllocationInfo(entryName, subEntryName, entry) + for entryName, entries := range tt.podEntries { + for subEntryName, entry := range entries { + stateImpl.SetAllocationInfo(entryName, subEntryName, entry) - if entries.IsPoolEntry() { - continue - } + if entries.IsPoolEntry() { + continue + } - pod := &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - UID: types.UID(entry.PodUid), - Name: entry.PodName, - Namespace: entry.PodNamespace, - Annotations: maputil.CopySS(entry.Annotations), - Labels: maputil.CopySS(entry.Labels), - }, - Spec: v1.PodSpec{ - Containers: []v1.Container{ - { - Name: entry.ContainerName, - }, + pod := &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + UID: types.UID(entry.PodUid), + Name: entry.PodName, + Namespace: entry.PodNamespace, + Annotations: maputil.CopySS(entry.Annotations), + Labels: maputil.CopySS(entry.Labels), + }, + Spec: v1.PodSpec{ + Containers: []v1.Container{ + { + Name: entry.ContainerName, }, }, - } + }, + } - pods = append(pods, pod) + pods = append(pods, pod) - if tt.wantEvictPodUIDSet.Has(entry.PodUid) { - candidatePods = append(candidatePods, pod) - } - - curLoad, found := tt.loads[entryName][subEntryName] - as.True(found) - fakeMetricsFetcher.SetContainerMetric(entryName, subEntryName, consts.MetricLoad1MinContainer, utilmetric.MetricData{Value: curLoad, Time: &now}) + if tt.wantEvictPodUIDSet.Has(entry.PodUid) { + candidatePods = append(candidatePods, pod) } + + curLoad, found := tt.loads[entryName][subEntryName] + as.True(found) + fakeMetricsFetcher.SetContainerMetric(entryName, subEntryName, consts.MetricLoad1MinContainer, utilmetric.MetricData{Value: curLoad, Time: &now}) } + } - plugin.(*CPUPressureLoadEviction).state = stateImpl + plugin.(*CPUPressureLoadEviction).state = stateImpl - plugin.(*CPUPressureLoadEviction).metaServer.MetricsFetcher = fakeMetricsFetcher + plugin.(*CPUPressureLoadEviction).metaServer.MetricsFetcher = fakeMetricsFetcher - plugin.(*CPUPressureLoadEviction).collectMetrics(context.Background()) + plugin.(*CPUPressureLoadEviction).collectMetrics(context.Background()) - metResp, err := plugin.ThresholdMet(context.Background(), &evictionpluginapi.Empty{}) - as.Nil(err) - as.NotNil(t, metResp) - - resp, err := plugin.GetTopEvictionPods(context.TODO(), &evictionpluginapi.GetTopEvictionPodsRequest{ - ActivePods: pods, - TopN: 1, - EvictionScope: consts.MetricLoad1MinContainer, - }) - assert.NoError(t, err) - assert.NotNil(t, resp) - - if metResp.MetType == evictionpluginapi.ThresholdMetType_HARD_MET { - as.Equal(candidatePods, resp.TargetPods) - tt.wantResp = &evictionpluginapi.GetTopEvictionPodsResponse{ - TargetPods: candidatePods, - } - } - as.Equal(tt.wantResp, resp) + metResp, err := plugin.ThresholdMet(context.Background(), &evictionpluginapi.Empty{}) + as.Nil(err) + as.NotNil(t, metResp) + + resp, err := plugin.GetTopEvictionPods(context.TODO(), &evictionpluginapi.GetTopEvictionPodsRequest{ + ActivePods: pods, + TopN: 1, + EvictionScope: consts.MetricLoad1MinContainer, }) + assert.NoError(t, err) + assert.NotNil(t, resp) + + if metResp.MetType == evictionpluginapi.ThresholdMetType_HARD_MET { + as.Equal(candidatePods, resp.TargetPods) + tt.wantResp = &evictionpluginapi.GetTopEvictionPodsResponse{ + TargetPods: candidatePods, + } + } + as.Equal(tt.wantResp, resp) } } @@ -1570,7 +1566,10 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + as := require.New(t) cpuTopology, err := machine.GenerateDummyCPUTopology(16, 2, 4) diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_suppression_test.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_suppression_test.go index b588badf0..e48da5193 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_suppression_test.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_suppression_test.go @@ -256,70 +256,68 @@ func TestCPUPressureSuppression_GetEvictPods(t *testing.T) { } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - stateImpl, err := makeState(cpuTopology) - as.Nil(err) + stateImpl, err := makeState(cpuTopology) + as.Nil(err) - pods := make([]*v1.Pod, 0, len(tt.podEntries)) + pods := make([]*v1.Pod, 0, len(tt.podEntries)) - for entryName, entries := range tt.podEntries { - for subEntryName, entry := range entries { - stateImpl.SetAllocationInfo(entryName, subEntryName, entry) + for entryName, entries := range tt.podEntries { + for subEntryName, entry := range entries { + stateImpl.SetAllocationInfo(entryName, subEntryName, entry) - if entries.IsPoolEntry() { - continue - } + if entries.IsPoolEntry() { + continue + } - pod := &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - UID: types.UID(entry.PodUid), - Name: entry.PodName, - Namespace: entry.PodNamespace, - Annotations: maputil.CopySS(entry.Annotations), - Labels: maputil.CopySS(entry.Labels), - }, - Spec: v1.PodSpec{ - Containers: []v1.Container{ - { - Name: entry.ContainerName, - Resources: v1.ResourceRequirements{ - Requests: v1.ResourceList{ - apiconsts.ReclaimedResourceMilliCPU: *resource.NewQuantity(int64(entry.RequestQuantity*1000), resource.DecimalSI), - }, - Limits: v1.ResourceList{ - apiconsts.ReclaimedResourceMilliCPU: *resource.NewQuantity(int64(entry.RequestQuantity*1000), resource.DecimalSI), - }, + pod := &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + UID: types.UID(entry.PodUid), + Name: entry.PodName, + Namespace: entry.PodNamespace, + Annotations: maputil.CopySS(entry.Annotations), + Labels: maputil.CopySS(entry.Labels), + }, + Spec: v1.PodSpec{ + Containers: []v1.Container{ + { + Name: entry.ContainerName, + Resources: v1.ResourceRequirements{ + Requests: v1.ResourceList{ + apiconsts.ReclaimedResourceMilliCPU: *resource.NewQuantity(int64(entry.RequestQuantity*1000), resource.DecimalSI), + }, + Limits: v1.ResourceList{ + apiconsts.ReclaimedResourceMilliCPU: *resource.NewQuantity(int64(entry.RequestQuantity*1000), resource.DecimalSI), }, }, }, }, - } - - pods = append(pods, pod) + }, } - } - plugin.(*CPUPressureSuppression).state = stateImpl + pods = append(pods, pod) + } + } - resp, err := plugin.GetEvictPods(context.TODO(), &evictionpluginapi.GetEvictPodsRequest{ - ActivePods: pods, - }) - assert.NoError(t, err) - assert.NotNil(t, resp) + plugin.(*CPUPressureSuppression).state = stateImpl - time.Sleep(defaultCPUMinSuppressionToleranceDuration) + resp, err := plugin.GetEvictPods(context.TODO(), &evictionpluginapi.GetEvictPodsRequest{ + ActivePods: pods, + }) + assert.NoError(t, err) + assert.NotNil(t, resp) - resp, err = plugin.GetEvictPods(context.TODO(), &evictionpluginapi.GetEvictPodsRequest{ - ActivePods: pods, - }) - assert.NoError(t, err) - assert.NotNil(t, resp) + time.Sleep(defaultCPUMinSuppressionToleranceDuration) - evictPodUIDSet := sets.String{} - for _, pod := range resp.EvictPods { - evictPodUIDSet.Insert(string(pod.Pod.GetUID())) - } - assert.Equal(t, tt.wantEvictPodUIDSet, evictPodUIDSet) + resp, err = plugin.GetEvictPods(context.TODO(), &evictionpluginapi.GetEvictPodsRequest{ + ActivePods: pods, }) + assert.NoError(t, err) + assert.NotNil(t, resp) + + evictPodUIDSet := sets.String{} + for _, pod := range resp.EvictPods { + evictPodUIDSet.Insert(string(pod.Pod.GetUID())) + } + assert.Equal(t, tt.wantEvictPodUIDSet, evictPodUIDSet) } } diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/state_test.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/state_test.go index 9097f1437..b60595e43 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/state_test.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/state_test.go @@ -17,6 +17,7 @@ limitations under the License. package state import ( + "fmt" "io/ioutil" "os" "strings" @@ -1424,7 +1425,7 @@ func TestNewCheckpointState(t *testing.T) { } // create temp dir - testingDir, err := ioutil.TempDir("", "dynamic_policy_state_test") + testingDir, err := ioutil.TempDir("", "TestNewCheckpointState") if err != nil { t.Fatal(err) } @@ -1435,33 +1436,31 @@ func TestNewCheckpointState(t *testing.T) { assert.NoError(t, err, "could not create testing checkpoint manager") for _, tc := range testCases { - t.Run(tc.description, func(t *testing.T) { - // ensure there is no previous checkpoint - require.NoError(t, cpm.RemoveCheckpoint(cpuPluginStateFileName), "could not remove testing checkpoint") + // ensure there is no previous checkpoint + require.NoError(t, cpm.RemoveCheckpoint(cpuPluginStateFileName), "could not remove testing checkpoint") - // prepare checkpoint for testing - if strings.TrimSpace(tc.checkpointContent) != "" { - checkpoint := &testutil.MockCheckpoint{Content: tc.checkpointContent} - require.NoError(t, cpm.CreateCheckpoint(cpuPluginStateFileName, checkpoint), "could not create testing checkpoint") - } + // prepare checkpoint for testing + if strings.TrimSpace(tc.checkpointContent) != "" { + checkpoint := &testutil.MockCheckpoint{Content: tc.checkpointContent} + require.NoError(t, cpm.CreateCheckpoint(cpuPluginStateFileName, checkpoint), "could not create testing checkpoint") + } - restoredState, err := NewCheckpointState(testingDir, cpuPluginStateFileName, policyName, cpuTopology, false) - if strings.TrimSpace(tc.expectedError) != "" { - require.Error(t, err) - require.Contains(t, err.Error(), "could not restore state from checkpoint:") - require.Contains(t, err.Error(), tc.expectedError) + restoredState, err := NewCheckpointState(testingDir, cpuPluginStateFileName, policyName, cpuTopology, false) + if strings.TrimSpace(tc.expectedError) != "" { + require.Error(t, err) + require.Contains(t, err.Error(), "could not restore state from checkpoint:") + require.Contains(t, err.Error(), tc.expectedError) - // test skip corruption - if strings.Contains(err.Error(), "checkpoint is corrupted") { - _, err = NewCheckpointState(testingDir, cpuPluginStateFileName, policyName, cpuTopology, true) - require.Nil(t, err) - } - } else { - require.NoError(t, err, "unexpected error while creating checkpointState") - // compare state after restoration with the one expected - assertStateEqual(t, restoredState, tc.expectedState) + // test skip corruption + if strings.Contains(err.Error(), "checkpoint is corrupted") { + _, err = NewCheckpointState(testingDir, cpuPluginStateFileName, policyName, cpuTopology, true) + require.Nil(t, err) } - }) + } else { + require.NoError(t, err, "unexpected error while creating checkpointState") + // compare state after restoration with the one expected + assertStateEqual(t, restoredState, tc.expectedState) + } } } @@ -1471,7 +1470,6 @@ func TestClearState(t *testing.T) { as := require.New(t) testName := "test" - cpuTopology, err := machine.GenerateDummyCPUTopology(16, 2, 4) as.Nil(err) @@ -1931,15 +1929,18 @@ func TestClearState(t *testing.T) { }, } - // create temp dir - testingDir, err := ioutil.TempDir("", "dynamic_policy_state_test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(testingDir) - - for _, tc := range testCases { + for i, tc := range testCases { + i, tc := i, tc t.Run(tc.description, func(t *testing.T) { + t.Parallel() + + // create temp dir + testingDir, err := ioutil.TempDir("", fmt.Sprintf("dynamic_policy_state_test_%d", i)) + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(testingDir) + state1, err := NewCheckpointState(testingDir, cpuPluginStateFileName, policyName, tc.cpuTopology, false) as.Nil(err) @@ -2429,7 +2430,10 @@ func TestCheckpointStateHelpers(t *testing.T) { defer os.RemoveAll(testingDir) for _, tc := range testCases { + tc := tc t.Run(tc.description, func(t *testing.T) { + t.Parallel() + state, err := NewCheckpointState(testingDir, cpuPluginStateFileName, policyName, tc.cpuTopology, false) as.Nil(err) diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/util_test.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/util_test.go index 26255e754..c2f7bda3c 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/util_test.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/util_test.go @@ -553,7 +553,9 @@ func TestGetSpecifiedPoolName(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() if got := GetSpecifiedPoolName(tt.args.qosLevel, tt.args.cpusetEnhancementValue); got != tt.want { t.Errorf("GetSpecifiedPoolName() = %v, want %v", got, tt.want) } diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/util_test.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/util_test.go index c8c34eed7..974b280dd 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/util_test.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/util_test.go @@ -58,7 +58,9 @@ func Test_updateAllocationInfoByReq(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() if err := updateAllocationInfoByReq(tt.args.req, tt.args.allocationInfo); (err != nil) != tt.wantErr { t.Errorf("updateAllocationInfoByReq() error = %v, wantErr %v", err, tt.wantErr) } diff --git a/pkg/agent/qrm-plugins/cpu/nativepolicy/calculator/cpu_assignment_test.go b/pkg/agent/qrm-plugins/cpu/nativepolicy/calculator/cpu_assignment_test.go index dd7ffb82d..c866cd1b2 100644 --- a/pkg/agent/qrm-plugins/cpu/nativepolicy/calculator/cpu_assignment_test.go +++ b/pkg/agent/qrm-plugins/cpu/nativepolicy/calculator/cpu_assignment_test.go @@ -570,6 +570,8 @@ var ( ) func TestCPUAccumulatorFreeSockets(t *testing.T) { + t.Parallel() + testCases := []struct { description string topo *machine.CPUTopology @@ -657,7 +659,10 @@ func TestCPUAccumulatorFreeSockets(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.description, func(t *testing.T) { + t.Parallel() + acc := newCPUAccumulator(tc.topo, tc.availableCPUs, 0) result := acc.freeSockets() sort.Ints(result) @@ -670,6 +675,8 @@ func TestCPUAccumulatorFreeSockets(t *testing.T) { } func TestCPUAccumulatorFreeNUMANodes(t *testing.T) { + t.Parallel() + testCases := []struct { description string topo *machine.CPUTopology @@ -757,7 +764,10 @@ func TestCPUAccumulatorFreeNUMANodes(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.description, func(t *testing.T) { + t.Parallel() + acc := newCPUAccumulator(tc.topo, tc.availableCPUs, 0) result := acc.freeNUMANodes() if !reflect.DeepEqual(result, tc.expect) { @@ -768,6 +778,8 @@ func TestCPUAccumulatorFreeNUMANodes(t *testing.T) { } func TestCPUAccumulatorFreeSocketsAndNUMANodes(t *testing.T) { + t.Parallel() + testCases := []struct { description string topo *machine.CPUTopology @@ -806,7 +818,10 @@ func TestCPUAccumulatorFreeSocketsAndNUMANodes(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.description, func(t *testing.T) { + t.Parallel() + acc := newCPUAccumulator(tc.topo, tc.availableCPUs, 0) resultNUMANodes := acc.freeNUMANodes() if !reflect.DeepEqual(resultNUMANodes, tc.expectNUMANodes) { @@ -821,6 +836,8 @@ func TestCPUAccumulatorFreeSocketsAndNUMANodes(t *testing.T) { } func TestCPUAccumulatorFreeCores(t *testing.T) { + t.Parallel() + testCases := []struct { description string topo *machine.CPUTopology @@ -878,7 +895,10 @@ func TestCPUAccumulatorFreeCores(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.description, func(t *testing.T) { + t.Parallel() + acc := newCPUAccumulator(tc.topo, tc.availableCPUs, 0) result := acc.freeCores() if !reflect.DeepEqual(result, tc.expect) { @@ -889,6 +909,8 @@ func TestCPUAccumulatorFreeCores(t *testing.T) { } func TestCPUAccumulatorFreeCPUs(t *testing.T) { + t.Parallel() + testCases := []struct { description string topo *machine.CPUTopology @@ -934,7 +956,10 @@ func TestCPUAccumulatorFreeCPUs(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.description, func(t *testing.T) { + t.Parallel() + acc := newCPUAccumulator(tc.topo, tc.availableCPUs, 0) result := acc.freeCPUs() if !reflect.DeepEqual(result, tc.expect) { @@ -945,6 +970,8 @@ func TestCPUAccumulatorFreeCPUs(t *testing.T) { } func TestCPUAccumulatorTake(t *testing.T) { + t.Parallel() + testCases := []struct { description string topo *machine.CPUTopology @@ -1020,7 +1047,10 @@ func TestCPUAccumulatorTake(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.description, func(t *testing.T) { + t.Parallel() + acc := newCPUAccumulator(tc.topo, tc.availableCPUs, tc.numCPUs) totalTaken := 0 for _, cpus := range tc.takeCPUs { @@ -1169,6 +1199,8 @@ func commonTakeByTopologyTestCases(t *testing.T) []takeByTopologyTestCase { } func TestTakeByTopologyNUMAPacked(t *testing.T) { + t.Parallel() + testCases := commonTakeByTopologyTestCases(t) testCases = append(testCases, []takeByTopologyTestCase{ { @@ -1198,7 +1230,10 @@ func TestTakeByTopologyNUMAPacked(t *testing.T) { }...) for _, tc := range testCases { + tc := tc t.Run(tc.description, func(t *testing.T) { + t.Parallel() + result, err := TakeByTopologyNUMAPacked(tc.topo, tc.availableCPUs, tc.numCPUs) if tc.expErr != "" && err.Error() != tc.expErr { t.Errorf("expected error to be [%v] but it was [%v]", tc.expErr, err) @@ -1306,6 +1341,8 @@ func commonTakeByTopologyExtendedTestCases(t *testing.T) []takeByTopologyExtende } func TestTakeByTopologyNUMADistributed(t *testing.T) { + t.Parallel() + testCases := commonTakeByTopologyExtendedTestCases(t) testCases = append(testCases, []takeByTopologyExtendedTestCase{ { @@ -1401,7 +1438,10 @@ func TestTakeByTopologyNUMADistributed(t *testing.T) { }...) for _, tc := range testCases { + tc := tc t.Run(tc.description, func(t *testing.T) { + t.Parallel() + result, err := TakeByTopologyNUMADistributed(tc.topo, tc.availableCPUs, tc.numCPUs, tc.cpuGroupSize) if err != nil { if tc.expErr == "" { diff --git a/pkg/agent/qrm-plugins/cpu/util/util_test.go b/pkg/agent/qrm-plugins/cpu/util/util_test.go index e09a28f63..44a905de7 100644 --- a/pkg/agent/qrm-plugins/cpu/util/util_test.go +++ b/pkg/agent/qrm-plugins/cpu/util/util_test.go @@ -116,7 +116,10 @@ func TestGetCoresReservedForSystem(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got, err := GetCoresReservedForSystem(tt.args.conf, tt.args.metaServer, tt.args.machineInfo, tt.args.allCPUs) if (err != nil) != tt.wantErr { t.Errorf("GetCoresReservedForSystem() error = %v, wantErr %v", err, tt.wantErr) @@ -188,7 +191,9 @@ func TestRegenerateHints(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() if got := RegenerateHints(tt.args.allocationInfo, tt.args.reqInt); !reflect.DeepEqual(got, tt.want) { t.Errorf("RegenerateHints() = %v, want %v", got, tt.want) } @@ -301,7 +306,10 @@ func TestPackAllocationResponse(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got, err := PackAllocationResponse(tt.args.allocationInfo, tt.args.resourceName, tt.args.ociPropertyName, tt.args.isNodeResource, tt.args.isScalarResource, tt.args.req) if (err != nil) != tt.wantErr { t.Errorf("PackAllocationResponse() error = %v, wantErr %v", err, tt.wantErr) diff --git a/pkg/agent/qrm-plugins/io/handlers/iocost/iocost_linux_test.go b/pkg/agent/qrm-plugins/io/handlers/iocost/iocost_linux_test.go index 4edd10ba7..01ee80e2b 100644 --- a/pkg/agent/qrm-plugins/io/handlers/iocost/iocost_linux_test.go +++ b/pkg/agent/qrm-plugins/io/handlers/iocost/iocost_linux_test.go @@ -141,6 +141,8 @@ func TestSetIOCost(t *testing.T) { }, nil, &dynamicconfig.DynamicAgentConfiguration{}, metrics.DummyMetrics{}, metaServer) } func Test_disableIOCost(t *testing.T) { + t.Parallel() + type args struct { conf *config.Configuration } @@ -186,13 +188,17 @@ func Test_disableIOCost(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() disableIOCost(tt.args.conf) }) } } func Test_applyIOCostConfig(t *testing.T) { + t.Parallel() + type args struct { conf *config.Configuration emitter metrics.MetricEmitter @@ -313,13 +319,17 @@ func Test_applyIOCostConfig(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() applyIOCostConfig(tt.args.conf, tt.args.emitter) }) } } func Test_reportDevicesIOCostVrate(t *testing.T) { + t.Parallel() + type args struct { emitter metrics.MetricEmitter } @@ -341,13 +351,17 @@ func Test_reportDevicesIOCostVrate(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() reportDevicesIOCostVrate(tt.args.emitter) }) } } func Test_applyIOCostModel(t *testing.T) { + t.Parallel() + type args struct { ioCostModelConfigs map[DevModel]*common.IOCostModelData devsIDToModel map[string]DevModel @@ -371,13 +385,17 @@ func Test_applyIOCostModel(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() applyIOCostModelWithDefault(tt.args.ioCostModelConfigs, tt.args.devsIDToModel) }) } } func TestApplyIOCostQoSWithDefault(t *testing.T) { + t.Parallel() + // Mocking the necessary dependencies ioCostQoSConfigs := make(map[DevModel]*common.IOCostQoSData) ioCostQoSConfigs[DevModelDefaultHDD] = &common.IOCostQoSData{Enable: 1} diff --git a/pkg/agent/qrm-plugins/io/handlers/iocost/utils_test.go b/pkg/agent/qrm-plugins/io/handlers/iocost/utils_test.go index 3e4388383..badfa70dc 100644 --- a/pkg/agent/qrm-plugins/io/handlers/iocost/utils_test.go +++ b/pkg/agent/qrm-plugins/io/handlers/iocost/utils_test.go @@ -31,6 +31,8 @@ import ( ) func TestGetDevicesIdToModel(t *testing.T) { + t.Parallel() + allDeviceNames, _ := getAllDeviceNames() type args struct { @@ -59,7 +61,9 @@ func TestGetDevicesIdToModel(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() _, err := getDevicesIdToModel(tt.args.deviceNames) if (err != nil) != tt.wantErr { t.Errorf("getDevicesIdToModel() error = %v, wantErr %v", err, tt.wantErr) @@ -70,6 +74,8 @@ func TestGetDevicesIdToModel(t *testing.T) { } func TestLoadJsonConfig(t *testing.T) { + t.Parallel() + type args struct { configAbsPath string configObject interface{} @@ -88,7 +94,9 @@ func TestLoadJsonConfig(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() if err := general.LoadJsonConfig(tt.args.configAbsPath, tt.args.configObject); (err != nil) != tt.wantErr { t.Errorf("LoadJsonConfig() error = %v, wantErr %v", err, tt.wantErr) } @@ -97,6 +105,8 @@ func TestLoadJsonConfig(t *testing.T) { } func TestGetDeviceNameFromID(t *testing.T) { + t.Parallel() + targetDevID := "1234" _, found, err := getDeviceNameFromID(targetDevID) @@ -105,6 +115,8 @@ func TestGetDeviceNameFromID(t *testing.T) { } func TestGetDeviceType(t *testing.T) { + t.Parallel() + testCases := []struct { deviceName string expectedType DeviceType diff --git a/pkg/agent/qrm-plugins/io/staticpolicy/policy_test.go b/pkg/agent/qrm-plugins/io/staticpolicy/policy_test.go index 59ed86854..aa2d30875 100644 --- a/pkg/agent/qrm-plugins/io/staticpolicy/policy_test.go +++ b/pkg/agent/qrm-plugins/io/staticpolicy/policy_test.go @@ -103,7 +103,10 @@ func TestNewStaticPolicy(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got, got1, err := NewStaticPolicy(tt.args.agentCtx, tt.args.conf, tt.args.in2, tt.args.agentName) if (err != nil) != tt.wantErr { t.Errorf("NewStaticPolicy() error = %v, wantErr %v", err, tt.wantErr) @@ -149,7 +152,10 @@ func TestStaticPolicy_Start(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + p := &StaticPolicy{ name: tt.fields.name, stopCh: tt.fields.stopCh, @@ -195,7 +201,10 @@ func TestStaticPolicy_Stop(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + p := &StaticPolicy{ name: tt.fields.name, stopCh: tt.fields.stopCh, @@ -241,7 +250,10 @@ func TestStaticPolicy_Name(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + p := &StaticPolicy{ name: tt.fields.name, stopCh: tt.fields.stopCh, @@ -287,7 +299,9 @@ func TestStaticPolicy_ResourceName(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() p := &StaticPolicy{ name: tt.fields.name, stopCh: tt.fields.stopCh, @@ -344,7 +358,10 @@ func TestStaticPolicy_GetTopologyHints(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + p := &StaticPolicy{ name: tt.fields.name, stopCh: tt.fields.stopCh, @@ -406,7 +423,10 @@ func TestStaticPolicy_RemovePod(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + p := &StaticPolicy{ name: tt.fields.name, stopCh: tt.fields.stopCh, @@ -468,7 +488,10 @@ func TestStaticPolicy_GetResourcesAllocation(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + p := &StaticPolicy{ name: tt.fields.name, stopCh: tt.fields.stopCh, @@ -530,7 +553,10 @@ func TestStaticPolicy_GetTopologyAwareResources(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + p := &StaticPolicy{ name: tt.fields.name, stopCh: tt.fields.stopCh, @@ -592,7 +618,10 @@ func TestStaticPolicy_GetTopologyAwareAllocatableResources(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + p := &StaticPolicy{ name: tt.fields.name, stopCh: tt.fields.stopCh, @@ -658,7 +687,10 @@ func TestStaticPolicy_GetResourcePluginOptions(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + p := &StaticPolicy{ name: tt.fields.name, stopCh: tt.fields.stopCh, @@ -728,7 +760,10 @@ func TestStaticPolicy_Allocate(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + p := &StaticPolicy{ name: tt.fields.name, stopCh: tt.fields.stopCh, @@ -790,7 +825,10 @@ func TestStaticPolicy_PreStartContainer(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + p := &StaticPolicy{ name: tt.fields.name, stopCh: tt.fields.stopCh, diff --git a/pkg/agent/qrm-plugins/memory/dynamicpolicy/oom/calculator_test.go b/pkg/agent/qrm-plugins/memory/dynamicpolicy/oom/calculator_test.go index e20adeb12..54ad8c644 100644 --- a/pkg/agent/qrm-plugins/memory/dynamicpolicy/oom/calculator_test.go +++ b/pkg/agent/qrm-plugins/memory/dynamicpolicy/oom/calculator_test.go @@ -116,7 +116,10 @@ func TestNativeOOMPriorityCalculator(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got, err := nativeOOMPriorityCalculator(qosConfig, tt.pod, 0) if (err != nil) != tt.wantErr { t.Errorf("nativeOOMPriorityCalculator() error = %v", err) diff --git a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_test.go b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_test.go index 24c305288..913a8ebd9 100644 --- a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_test.go +++ b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_test.go @@ -2784,7 +2784,10 @@ func TestDynamicPolicy_ListContainers(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got, err := dynamicPolicy.ListContainers(tt.args.in0, tt.args.in1) if (err != nil) != tt.wantErr { t.Errorf("DynamicPolicy.ListContainers() error = %v, wantErr %v", err, tt.wantErr) @@ -2889,7 +2892,9 @@ func TestDynamicPolicy_hasLastLevelEnhancementKey(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() if got := dynamicPolicy.hasLastLevelEnhancementKey(tt.args.lastLevelEnhancementKey, tt.args.podUID); got != tt.want { t.Errorf("DynamicPolicy.hasLastLevelEnhancementKey() = %v, want %v", got, tt.want) } @@ -3204,7 +3209,10 @@ func TestPollOOMBPFInit(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + tmpDir, err := ioutil.TempDir("", "checkpoint-TestPollOOMBPFInit") as.Nil(err) defer os.RemoveAll(tmpDir) @@ -3243,6 +3251,8 @@ func TestPollOOMBPFInit(t *testing.T) { } func TestDynamicPolicy_adjustAllocationEntries(t *testing.T) { + t.Parallel() + metaServer := makeMetaServer() tmpDir, err := ioutil.TempDir("", "checkpoint-TestDynamicPolicy_adjustAllocationEntries") assert.NoError(t, err) @@ -3395,7 +3405,9 @@ func TestDynamicPolicy_adjustAllocationEntries(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() dynamicPolicy, err := getTestDynamicPolicyWithInitialization(cpuTopology, machineInfo, tmpDir) assert.NoError(t, err) diff --git a/pkg/agent/qrm-plugins/memory/dynamicpolicy/util_linux_amd64_test.go b/pkg/agent/qrm-plugins/memory/dynamicpolicy/util_linux_amd64_test.go index be8192c54..5f2cd38b2 100644 --- a/pkg/agent/qrm-plugins/memory/dynamicpolicy/util_linux_amd64_test.go +++ b/pkg/agent/qrm-plugins/memory/dynamicpolicy/util_linux_amd64_test.go @@ -107,7 +107,10 @@ func TestGetNumaNodeFreeMemMB(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + tmpDir := t.TempDir() var numas []int for numa, pages := range tt.numaPages { @@ -142,7 +145,10 @@ func TestGetNumaNodeFreeMemMB_VMStatFileNotFound(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + tmpDir := t.TempDir() _, err := getNumasFreeMemRatio(tmpDir, []int{0}) if (err != nil) != tt.wantErr { @@ -191,7 +197,10 @@ func TestGetNumaNodeFreeMemMB_GetFreePagesFailed(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + tmpDir := t.TempDir() generateNodeVMStatFile(t, tmpDir, 0, tt.content) _, err := getNumasFreeMemRatio(tmpDir, []int{0}) @@ -206,6 +215,8 @@ func TestGetNumaNodeFreeMemMB_GetFreePagesFailed(t *testing.T) { } func TestGetProcessPageStats(t *testing.T) { + t.Parallel() + tests := []struct { name string pid int @@ -284,7 +295,10 @@ VmFlags: rd mr mw me dw sd } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + tmpDir := t.TempDir() generatePidSmapsFile(t, tmpDir, tt.pid, tt.content) got, err := getProcessPageStats(tmpDir, tt.pid) @@ -302,6 +316,8 @@ VmFlags: rd mr mw me dw sd } func TestGetProcessPageStats_SmapsFileNotFound(t *testing.T) { + t.Parallel() + tests := []struct { name string wantErr bool @@ -315,7 +331,10 @@ func TestGetProcessPageStats_SmapsFileNotFound(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + tmpDir := t.TempDir() _, err := getProcessPageStats(tmpDir, 12345) if (err != nil) != tt.wantErr { @@ -382,7 +401,10 @@ Pss: 4 kB } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + tmpDir := t.TempDir() generatePidSmapsFile(t, tmpDir, 12345, tt.content) got, err := getProcessPageStats(tmpDir, 12345) @@ -442,7 +464,10 @@ VmFlags: rd mr mw me dw sd } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + tmpDir := t.TempDir() generatePidSmapsFile(t, tmpDir, tt.pid, tt.content) err := MovePagesForProcess(context.Background(), tmpDir, tt.pid, tt.srcNumas, tt.destNumas) @@ -460,6 +485,7 @@ VmFlags: rd mr mw me dw sd } func TestMovePagesForContainer(t *testing.T) { + t.Parallel() err := MovePagesForContainer(context.Background(), "pod123", "container123", machine.NewCPUSet([]int{1, 2}...), machine.NewCPUSet([]int{1, 2}...)) assert.NilError(t, err) } diff --git a/pkg/agent/qrm-plugins/memory/dynamicpolicy/util_test.go b/pkg/agent/qrm-plugins/memory/dynamicpolicy/util_test.go index 32decbc66..673e3fe39 100644 --- a/pkg/agent/qrm-plugins/memory/dynamicpolicy/util_test.go +++ b/pkg/agent/qrm-plugins/memory/dynamicpolicy/util_test.go @@ -24,6 +24,8 @@ import ( ) func TestGetFullyDropCacheBytes(t *testing.T) { + t.Parallel() + type args struct { container *v1.Container } @@ -70,7 +72,9 @@ func TestGetFullyDropCacheBytes(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() if got := GetFullyDropCacheBytes(tt.args.container); got != tt.want { t.Errorf("GetFullyDropCacheBytes() = %v, want %v", got, tt.want) } diff --git a/pkg/agent/resourcemanager/fetcher/kubelet/topology/topology_adapter_test.go b/pkg/agent/resourcemanager/fetcher/kubelet/topology/topology_adapter_test.go index af2be7a59..d570894f9 100644 --- a/pkg/agent/resourcemanager/fetcher/kubelet/topology/topology_adapter_test.go +++ b/pkg/agent/resourcemanager/fetcher/kubelet/topology/topology_adapter_test.go @@ -1267,7 +1267,10 @@ func Test_getZoneAllocationsByPodResources(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + qosConf := generic.NewQoSConfiguration() p := &topologyAdapterImpl{ numaSocketZoneNodeMap: tt.args.numaSocketZoneNodeMap, @@ -1813,7 +1816,10 @@ func Test_getZoneResourcesByAllocatableResources(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + p := &topologyAdapterImpl{ metaServer: tt.args.metaServer, numaSocketZoneNodeMap: tt.args.numaSocketZoneNodeMap, @@ -2060,7 +2066,10 @@ func Test_podResourcesServerTopologyAdapterImpl_GetTopologyZones_ReportRDMATopol }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + p := topologyAdapterImpl{ client: &fakePodResourcesListerClient{ ListPodResourcesResponse: tt.fields.listPodResources, @@ -2875,7 +2884,9 @@ func Test_podResourcesServerTopologyAdapterImpl_GetTopologyZones(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() p := &topologyAdapterImpl{ client: &fakePodResourcesListerClient{ diff --git a/pkg/agent/resourcemanager/fetcher/plugin/endpoint_test.go b/pkg/agent/resourcemanager/fetcher/plugin/endpoint_test.go index f9b045a20..976f3e9da 100644 --- a/pkg/agent/resourcemanager/fetcher/plugin/endpoint_test.go +++ b/pkg/agent/resourcemanager/fetcher/plugin/endpoint_test.go @@ -55,6 +55,7 @@ func TestNewEndpoint(t *testing.T) { } func TestRun(t *testing.T) { + t.Parallel() socket := path.Join("/tmp/TestRun") content := []*v1alpha1.ReportContent{ diff --git a/pkg/agent/resourcemanager/reporter/cnr/cnrreporter_test.go b/pkg/agent/resourcemanager/reporter/cnr/cnrreporter_test.go index 1caa93c1f..97abd3bd2 100644 --- a/pkg/agent/resourcemanager/reporter/cnr/cnrreporter_test.go +++ b/pkg/agent/resourcemanager/reporter/cnr/cnrreporter_test.go @@ -368,7 +368,9 @@ func Test_parseReportFieldToCNR(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() got, err := parseReportFieldToCNR(tt.args.cnr, tt.args.reportField, syntax.SimpleMergeTwoValues) if (err != nil) != tt.wantErr { t.Errorf("parseReportFieldToCNR() error = %v, wantErr %v", err, tt.wantErr) @@ -504,7 +506,9 @@ func Test_initializeCNRFields(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() if err := initializeFieldToCNR(tt.args.cnr, tt.args.field); (err != nil) != tt.wantErr { t.Errorf("initializeFieldToCNR() error = %v, wantErr %v", err, tt.wantErr) } @@ -590,7 +594,10 @@ func Test_cnrReporterImpl_Update(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + r := generateTestReporter(t, tt.fields.defaultCNR) err := r.(cnr.CNRFetcher).RegisterNotifier("test-notifier", cnr.CNRNotifierStub{}) require.NoError(t, err) diff --git a/pkg/agent/resourcemanager/reporter/manager_test.go b/pkg/agent/resourcemanager/reporter/manager_test.go index 372a66f26..d5c58a4c3 100644 --- a/pkg/agent/resourcemanager/reporter/manager_test.go +++ b/pkg/agent/resourcemanager/reporter/manager_test.go @@ -145,7 +145,9 @@ func Test_aggregateReportFieldsByGVK(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() if got := aggregateReportFieldsByGVK(tt.args.reportResponses); !reflect.DeepEqual(got, tt.want) { t.Errorf("aggregateReportFieldsByGVK() = %v, want %v", got, tt.want) } @@ -201,7 +203,9 @@ func Test_managerImpl_PushContents(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() r := &managerImpl{ conf: tt.fields.conf, reporters: tt.fields.reporters, @@ -237,7 +241,9 @@ func Test_managerImpl_Run(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() r := &managerImpl{ conf: tt.fields.conf, reporters: tt.fields.reporters, @@ -300,7 +306,9 @@ func Test_managerImpl_convertReportFieldsIfNeeded(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() r := &managerImpl{ converters: tt.fields.converters, } diff --git a/pkg/agent/sysadvisor/metacache/metacache_test.go b/pkg/agent/sysadvisor/metacache/metacache_test.go index 4d6b98e5e..d192de830 100644 --- a/pkg/agent/sysadvisor/metacache/metacache_test.go +++ b/pkg/agent/sysadvisor/metacache/metacache_test.go @@ -126,7 +126,9 @@ func TestMetaCacheImp_GetFilteredInferenceResult(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() mc := &MetaCacheImp{ emitter: tt.fields.emitter, modelToResult: tt.fields.modelToResult, @@ -175,7 +177,10 @@ func TestMetaCacheImp_GetInferenceResult(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + mc := &MetaCacheImp{ emitter: tt.fields.emitter, modelToResult: tt.fields.modelToResult, @@ -224,7 +229,10 @@ func TestMetaCacheImp_SetInferenceResult(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + mc := &MetaCacheImp{ emitter: tt.fields.emitter, modelToResult: tt.fields.modelToResult, @@ -247,6 +255,8 @@ func TestMetaCacheImp_SetInferenceResult(t *testing.T) { } func TestRangeAndDeleteContainerWithSafeTime(t *testing.T) { + t.Parallel() + testDir := "/tmp/mc-test-range-delete" checkpointManager, err := checkpointmanager.NewCheckpointManager(testDir) require.NoError(t, err, "failed to create checkpoint manager") diff --git a/pkg/agent/sysadvisor/plugin/inference/inference_test.go b/pkg/agent/sysadvisor/plugin/inference/inference_test.go index afe358758..2eeaeab94 100644 --- a/pkg/agent/sysadvisor/plugin/inference/inference_test.go +++ b/pkg/agent/sysadvisor/plugin/inference/inference_test.go @@ -73,7 +73,9 @@ func TestNewInferencePlugin(t *testing.T) { NewNilModelResultFetcher) for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() _, err := NewInferencePlugin(tt.args.pluginName, tt.args.conf, tt.args.extraConf, tt.args.emitterPool, tt.args.metaServer, tt.args.metaCache) if (err != nil) != tt.wantErr { t.Errorf("NewInferencePlugin() error = %v, wantErr %v", err, tt.wantErr) @@ -116,7 +118,10 @@ func TestInferencePlugin_Run(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + var cancel context.CancelFunc tt.args.ctx, cancel = context.WithCancel(context.Background()) infp := &InferencePlugin{ @@ -165,7 +170,10 @@ func TestInferencePlugin_Name(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + infp := &InferencePlugin{ name: tt.fields.name, period: tt.fields.period, @@ -213,7 +221,10 @@ func TestInferencePlugin_Init(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + infp := &InferencePlugin{ name: tt.fields.name, period: tt.fields.period, @@ -263,7 +274,9 @@ func TestInferencePlugin_fetchModelResult(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() infp := &InferencePlugin{ name: tt.fields.name, period: tt.fields.period, diff --git a/pkg/agent/sysadvisor/plugin/inference/modelresultfetcher/borwein/borwein_test.go b/pkg/agent/sysadvisor/plugin/inference/modelresultfetcher/borwein/borwein_test.go index f3bace6ab..dca0c0f82 100644 --- a/pkg/agent/sysadvisor/plugin/inference/modelresultfetcher/borwein/borwein_test.go +++ b/pkg/agent/sysadvisor/plugin/inference/modelresultfetcher/borwein/borwein_test.go @@ -125,7 +125,10 @@ func TestNativeGetNodeFeatureValue(t *testing.T) { } nowTimestamp := time.Now().Unix() for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + clientSet := generateTestGenericClientSet([]runtime.Object{&v1.Node{ ObjectMeta: metav1.ObjectMeta{ Name: nodeName, @@ -193,7 +196,10 @@ func TestNativeGetContainerFeatureValue(t *testing.T) { } nowTimestamp := time.Now().Unix() for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got, err := nativeGetContainerFeatureValue(nowTimestamp, tt.args.podUID, tt.args.containerName, tt.args.featureName, metaServer, &metacache.MetaCacheImp{MetricsReader: metaServer.MetricsFetcher}) @@ -320,7 +326,10 @@ func TestBorweinModelResultFetcher_FetchModelResult(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + bmrf := &BorweinModelResultFetcher{ name: tt.fields.name, qosConfig: tt.fields.qosConfig, @@ -476,7 +485,10 @@ func TestBorweinModelResultFetcher_parseInferenceRespForPods(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + bmrf := &BorweinModelResultFetcher{ name: tt.fields.name, qosConfig: tt.fields.qosConfig, @@ -629,7 +641,10 @@ func TestBorweinModelResultFetcher_getInferenceRequestForPods(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + bmrf := &BorweinModelResultFetcher{ name: tt.fields.name, qosConfig: tt.fields.qosConfig, @@ -652,6 +667,7 @@ func TestBorweinModelResultFetcher_getInferenceRequestForPods(t *testing.T) { func TestNewBorweinModelResultFetcher(t *testing.T) { t.Parallel() + checkpointDir, err := ioutil.TempDir("", "checkpoint-NewBorweinModelResultFetcher") require.NoError(t, err) defer func() { _ = os.RemoveAll(checkpointDir) }() @@ -809,38 +825,36 @@ func TestNewBorweinModelResultFetcher(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if tt.args.conf != nil { - tt.args.conf.PolicyRama.EnableBorweinModelResultFetcher = tt.args.enableBorweinModelResultFetcher - } - - var svr *grpc.Server - if tt.args.inferenceServiceSocketAbsPath != "" { - svr, err = RunFakeInferenceSvr(tt.args.inferenceServiceSocketAbsPath) - require.NoError(t, err) - conf.BorweinConfiguration.InferenceServiceSocketAbsPath = tt.args.inferenceServiceSocketAbsPath - } - - fetcher, err := NewBorweinModelResultFetcher(tt.args.fetcherName, tt.args.conf, tt.args.extraConf, tt.args.emitterPool, tt.args.metaServer, tt.args.metaCache) - if (err != nil) != tt.wantErr { - t.Errorf("NewBorweinModelResultFetcher() error = %v, wantErr %v", err, tt.wantErr) - if svr != nil { - svr.Stop() - } - return - } else if !tt.args.enableBorweinModelResultFetcher { - require.Nil(t, fetcher) - if svr != nil { - svr.Stop() - } - return + if tt.args.conf != nil { + tt.args.conf.PolicyRama.EnableBorweinModelResultFetcher = tt.args.enableBorweinModelResultFetcher + } + + var svr *grpc.Server + if tt.args.inferenceServiceSocketAbsPath != "" { + svr, err = RunFakeInferenceSvr(tt.args.inferenceServiceSocketAbsPath) + require.NoError(t, err) + conf.BorweinConfiguration.InferenceServiceSocketAbsPath = tt.args.inferenceServiceSocketAbsPath + } + + fetcher, err := NewBorweinModelResultFetcher(tt.args.fetcherName, tt.args.conf, tt.args.extraConf, tt.args.emitterPool, tt.args.metaServer, tt.args.metaCache) + if (err != nil) != tt.wantErr { + t.Errorf("NewBorweinModelResultFetcher() error = %v, wantErr %v", err, tt.wantErr) + if svr != nil { + svr.Stop() } - + return + } else if !tt.args.enableBorweinModelResultFetcher { + require.Nil(t, fetcher) if svr != nil { svr.Stop() - conf.BorweinConfiguration.InferenceServiceSocketAbsPath = "" } - }) + return + } + + if svr != nil { + svr.Stop() + conf.BorweinConfiguration.InferenceServiceSocketAbsPath = "" + } } } diff --git a/pkg/agent/sysadvisor/plugin/qosaware/reporter/manager/resource/generic_test.go b/pkg/agent/sysadvisor/plugin/qosaware/reporter/manager/resource/generic_test.go index 5109f9f47..68247271c 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/reporter/manager/resource/generic_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/reporter/manager/resource/generic_test.go @@ -70,7 +70,9 @@ func TestNewGenericHeadroomManager(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() NewGenericHeadroomManager(tt.args.name, tt.args.useMilliValue, tt.args.reportMillValue, tt.args.syncPeriod, tt.args.headroomAdvisor, tt.args.emitter, tt.args.slidingWindowOptions, tt.args.getReclaimOptionsFunc) diff --git a/pkg/agent/sysadvisor/plugin/qosaware/reporter/nodemetric_reporter.go b/pkg/agent/sysadvisor/plugin/qosaware/reporter/nodemetric_reporter.go index 6d98649a5..d6e0f05df 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/reporter/nodemetric_reporter.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/reporter/nodemetric_reporter.go @@ -98,6 +98,8 @@ func (r *nodeMetricsReporterImpl) Run(ctx context.Context) { type nodeMetricsReporterPlugin struct { sync.RWMutex + started bool + metaServer *metaserver.MetaServer metaReader metacache.MetaReader emitter metrics.MetricEmitter @@ -151,6 +153,18 @@ func (p *nodeMetricsReporterPlugin) Name() string { } func (p *nodeMetricsReporterPlugin) Start() (err error) { + p.Lock() + defer func() { + if err == nil { + p.started = true + } + p.Unlock() + }() + + if p.started { + return + } + p.stop = make(chan struct{}) general.RegisterHeartbeatCheck(nodeMetricsReporterPluginName, healthCheckTolerationDuration, general.HealthzCheckStateNotReady, healthCheckTolerationDuration) go wait.Until(p.updateNodeMetrics, p.syncPeriod, p.stop) @@ -158,6 +172,18 @@ func (p *nodeMetricsReporterPlugin) Start() (err error) { } func (p *nodeMetricsReporterPlugin) Stop() error { + p.Lock() + defer func() { + p.started = false + p.Unlock() + }() + + // plugin.Stop may be called before plugin.Start or multiple times, + // we should ensure cancel function exist + if !p.started { + return nil + } + if p.stop != nil { close(p.stop) } diff --git a/pkg/agent/sysadvisor/plugin/qosaware/reporter/nodemetric_reporter_test.go b/pkg/agent/sysadvisor/plugin/qosaware/reporter/nodemetric_reporter_test.go index 33e84ca57..f6fe067e0 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/reporter/nodemetric_reporter_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/reporter/nodemetric_reporter_test.go @@ -318,7 +318,10 @@ func TestNodeMetricUpdate(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + conf := generateTestConfiguration(t, regDir, ckDir, statDir) clientSet := generateTestGenericClientSet(nil, nil) metaServer := generateTestMetaServer(clientSet, conf, tt.args.pods...) diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/advisor_test.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/advisor_test.go index 8f18ba21a..0d3892c71 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/advisor_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/advisor_test.go @@ -991,7 +991,10 @@ func TestAdvisorUpdate(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + now := time.Now() ckDir, err := ioutil.TempDir("", "checkpoint-TestAdvisorUpdate") diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/headroomassembler/assembler_common_test.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/headroomassembler/assembler_common_test.go index 546244f6b..b4ae8286e 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/headroomassembler/assembler_common_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/headroomassembler/assembler_common_test.go @@ -332,7 +332,10 @@ func TestHeadroomAssemblerCommon_GetHeadroom(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + ckDir, err := ioutil.TempDir("", "checkpoint-TestHeadroomAssemblerCommon_GetHeadroom") require.NoError(t, err) defer os.RemoveAll(ckDir) diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/provisionassembler/assembler_test.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/provisionassembler/assembler_test.go index 0727836c3..d99efc3bc 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/provisionassembler/assembler_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/provisionassembler/assembler_test.go @@ -84,7 +84,9 @@ func TestRegulatePoolSizes(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() regulatePoolSizes(tt.poolSizes, tt.available, tt.enableReclaim) assert.Equal(t, tt.expectedPoolSizes, tt.poolSizes) }) diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/isolation/isolator_test.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/isolation/isolator_test.go index 734a0f14d..2d29c7243 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/isolation/isolator_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/isolation/isolator_test.go @@ -382,15 +382,13 @@ func TestLoadIsolator(t *testing.T) { expects: []string{"uid2", "uid5", "uid6"}, }, } { - t.Run(tc.comment, func(t *testing.T) { - t.Logf("test cases: %v", tc.comment) + t.Logf("test cases: %v", tc.comment) - conf.CPUIsolationConfiguration = tc.conf - loader := NewLoadIsolator(conf, struct{}{}, metrics.DummyMetrics{}, metaCache, metaServer) + conf.CPUIsolationConfiguration = tc.conf + loader := NewLoadIsolator(conf, struct{}{}, metrics.DummyMetrics{}, metaCache, metaServer) - res := loader.GetIsolatedPods() - assert.EqualValues(t, tc.expects, res) - }) + res := loader.GetIsolatedPods() + assert.EqualValues(t, tc.expects, res) } for i := range containers { @@ -451,22 +449,20 @@ func TestLoadIsolator(t *testing.T) { expects: []string{"uid5", "uid6", "uid7", "uid8"}, }, } { - t.Run(tc.comment, func(t *testing.T) { - t.Logf("test cases: %v", tc.comment) - - conf.CPUIsolationConfiguration = tc.conf - loader := NewLoadIsolator(conf, struct{}{}, metrics.DummyMetrics{}, metaCache, metaServer) - - now := time.Now() - for i := 0; i < 8; i++ { - loader.(*LoadIsolator).states.Store(fmt.Sprintf("uid%v", i), containerIsolationState{ - lockedOutFirstObserved: &now, - }) - } - time.Sleep(time.Millisecond * 10) - - res := loader.GetIsolatedPods() - assert.EqualValues(t, tc.expects, res) - }) + t.Logf("test cases: %v", tc.comment) + + conf.CPUIsolationConfiguration = tc.conf + loader := NewLoadIsolator(conf, struct{}{}, metrics.DummyMetrics{}, metaCache, metaServer) + + now := time.Now() + for i := 0; i < 8; i++ { + loader.(*LoadIsolator).states.Store(fmt.Sprintf("uid%v", i), containerIsolationState{ + lockedOutFirstObserved: &now, + }) + } + time.Sleep(time.Millisecond * 10) + + res := loader.GetIsolatedPods() + assert.EqualValues(t, tc.expects, res) } } diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/headroompolicy/policy_canonical_test.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/headroompolicy/policy_canonical_test.go index 00f1a3de9..837d6b4bb 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/headroompolicy/policy_canonical_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/headroompolicy/policy_canonical_test.go @@ -264,7 +264,10 @@ func TestPolicyCanonical(t *testing.T) { } policy.metaServer.MetaAgent.SetPodFetcher(constructPodFetcherCanonical(podNames)) + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + policy.SetEssentials(tt.resourceEssentials) err := policy.Update() assert.NoError(t, err) diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/headroompolicy/policy_numa_exclusive_test.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/headroompolicy/policy_numa_exclusive_test.go index f8b427166..2ccc4c5f3 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/headroompolicy/policy_numa_exclusive_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/headroompolicy/policy_numa_exclusive_test.go @@ -264,7 +264,10 @@ func TestPolicyNumaExclusive(t *testing.T) { } policy.metaServer.MetaAgent.SetPodFetcher(constructPodFetcherNumaExclusive(podNames)) + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + policy.SetEssentials(tt.resourceEssentials) err := policy.Update() assert.NoError(t, err) diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/provisionpolicy/policy_canonical_test.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/provisionpolicy/policy_canonical_test.go index 80e119c8f..9ef3c4dfe 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/provisionpolicy/policy_canonical_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/provisionpolicy/policy_canonical_test.go @@ -329,7 +329,10 @@ func TestPolicyCanonical(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + checkpointDir, err := os.MkdirTemp("", "checkpoint") require.NoError(t, err) defer func() { _ = os.RemoveAll(checkpointDir) }() diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/provisionpolicy/policy_rama_test.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/provisionpolicy/policy_rama_test.go index f5209afa7..0cf6e7503 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/provisionpolicy/policy_rama_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/provisionpolicy/policy_rama_test.go @@ -385,7 +385,10 @@ func TestPolicyRama(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + checkpointDir, err := os.MkdirTemp("", "checkpoint") require.NoError(t, err) defer func() { _ = os.RemoveAll(checkpointDir) }() diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region_test.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region_test.go index d2fd95297..8d7f14dbe 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region_test.go @@ -116,7 +116,10 @@ func TestGetRegionNameFromMetaCache(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + conf, err := options.NewOptions().Config() assert.NoError(t, err) conf.GenericSysAdvisorConfiguration.StateFileDirectory = os.TempDir() diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/helper/memory_test.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/helper/memory_test.go index 2d26c8c6b..f5904a981 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/helper/memory_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/helper/memory_test.go @@ -293,7 +293,10 @@ func TestGetAvailableNUMAsAndReclaimedCores(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + conf, metaReader, metaServer := tt.setup() gotNUMAs, gotContainers, err := GetAvailableNUMAsAndReclaimedCores(conf, metaReader, metaServer) diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/helper/modelctrl/borwein/borwein_test.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/helper/modelctrl/borwein/borwein_test.go index 66418d71e..2a9cafdec 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/helper/modelctrl/borwein/borwein_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/helper/modelctrl/borwein/borwein_test.go @@ -179,7 +179,10 @@ func TestNewBorweinController(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got := NewBorweinController(tt.args.regionName, tt.args.regionType, tt.args.ownerPoolName, tt.args.conf, tt.args.metaReader, metrics.DummyMetrics{}) require.True(t, reflect.DeepEqual(got.regionName, tt.want.regionName)) require.True(t, reflect.DeepEqual(got.regionType, tt.want.regionType)) @@ -329,7 +332,10 @@ func Test_updateCPUSchedWaitIndicatorOffset(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + mc.SetInferenceResult(borweinconsts.ModelNameBorwein, tt.args.inferenceResults) got, err := updateCPUSchedWaitIndicatorOffset(tt.args.podSet, tt.args.currentIndicatorOffset, tt.args.borweinParameter, tt.args.metaReader) if (err != nil) != tt.wantErr { @@ -440,7 +446,10 @@ func TestBorweinController_updateIndicatorOffsets(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + bc := &BorweinController{ regionName: tt.fields.regionName, regionType: tt.fields.regionType, @@ -457,6 +466,7 @@ func TestBorweinController_updateIndicatorOffsets(t *testing.T) { func TestBorweinController_getUpdatedIndicators(t *testing.T) { t.Parallel() + podUID := "test-pod-uid" podName := "test-pod" containerName := "test-container" @@ -578,7 +588,10 @@ func TestBorweinController_getUpdatedIndicators(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + mc.SetInferenceResult(borweinconsts.ModelNameBorwein, tt.args.inferenceResults) bc := &BorweinController{ regionName: tt.fields.regionName, @@ -598,6 +611,7 @@ func TestBorweinController_getUpdatedIndicators(t *testing.T) { func TestBorweinController_GetUpdatedIndicators(t *testing.T) { t.Parallel() + podUID := "test-pod-uid" podName := "test-pod" containerName := "test-container" @@ -723,7 +737,10 @@ func TestBorweinController_GetUpdatedIndicators(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + mc.SetInferenceResult(borweinconsts.ModelNameBorwein, tt.args.inferenceResults) bc := &BorweinController{ regionName: tt.fields.regionName, @@ -769,7 +786,10 @@ func TestBorweinController_ResetIndicatorOffsets(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + bc := &BorweinController{ indicatorOffsets: tt.fields.indicatorOffsets, } diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/advisor_test.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/advisor_test.go index 69c109515..8a6555aa0 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/advisor_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/advisor_test.go @@ -1875,7 +1875,10 @@ func TestUpdate(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + ckDir, err := ioutil.TempDir("", "checkpoint-TestUpdate") require.NoError(t, err) defer os.RemoveAll(ckDir) diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/headroompolicy/policy_canonical_test.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/headroompolicy/policy_canonical_test.go index a61753f04..4f59be5d3 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/headroompolicy/policy_canonical_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/headroompolicy/policy_canonical_test.go @@ -497,7 +497,10 @@ func TestPolicyCanonical_calculateMemoryBuffer(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + ckDir, err := ioutil.TempDir("", "checkpoint-TestPolicyCanonical_calculateMemoryBuffer") require.NoError(t, err) defer os.RemoveAll(ckDir) diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/headroompolicy/policy_numa_aware_test.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/headroompolicy/policy_numa_aware_test.go index 2bf6814d6..10fae2b66 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/headroompolicy/policy_numa_aware_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/headroompolicy/policy_numa_aware_test.go @@ -197,7 +197,10 @@ func TestPolicyNUMAAware(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + ckDir, err := ioutil.TempDir("", "checkpoint-TestPolicyNUMAAware") require.NoError(t, err) defer os.RemoveAll(ckDir) diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/plugin/provisioner/policy/policy_canonical_test.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/plugin/provisioner/policy/policy_canonical_test.go index 0d476bcc5..70532b352 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/plugin/provisioner/policy/policy_canonical_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/plugin/provisioner/policy/policy_canonical_test.go @@ -324,7 +324,10 @@ func TestPolicyCanonical(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + ckDir, err := ioutil.TempDir("", "checkpoint-TestProvisionPolicyCanonical") require.NoError(t, err) defer os.RemoveAll(ckDir) diff --git a/pkg/agent/sysadvisor/plugin/qosaware/server/cpu_server_test.go b/pkg/agent/sysadvisor/plugin/qosaware/server/cpu_server_test.go index a3045c335..a5d520779 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/server/cpu_server_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/server/cpu_server_test.go @@ -150,7 +150,10 @@ func TestCPUServerAddContainer(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + cs := newTestCPUServer(t, []*v1.Pod{}) got, err := cs.AddContainer(context.Background(), tt.request) if (err != nil) != tt.wantErr { @@ -189,7 +192,10 @@ func TestCPUServerRemovePod(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + cs := newTestCPUServer(t, []*v1.Pod{}) got, err := cs.RemovePod(context.Background(), tt.request) if (err != nil) != tt.wantErr { @@ -1125,7 +1131,10 @@ func TestCPUServerListAndWatch(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + cs := newTestCPUServer(t, []*v1.Pod{}) s := &mockCPUServerService_ListAndWatchServer{ResultsChan: make(chan *cpuadvisor.ListAndWatchResponse)} for _, info := range tt.infos { diff --git a/pkg/agent/sysadvisor/plugin/qosaware/server/memory_server_test.go b/pkg/agent/sysadvisor/plugin/qosaware/server/memory_server_test.go index bf73527e8..64ac2f057 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/server/memory_server_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/server/memory_server_test.go @@ -149,7 +149,10 @@ func TestListContainers(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + serv := grpc.NewServer() mockQRMServiceServer := &MockQRMServiceServer{containers: tt.containers, listErr: tt.listErr} @@ -290,7 +293,10 @@ func TestMemoryServerListAndWatch(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + cs := newTestMemoryServer(t, []*v1.Pod{}) s := &mockMemoryServerService_ListAndWatchServer{ResultsChan: make(chan *advisorsvc.ListAndWatchResponse)} for _, info := range tt.infos { diff --git a/pkg/agent/sysadvisor/test/sysadvisor_test.go b/pkg/agent/sysadvisor/test/sysadvisor_test.go index 4551c1f18..46554b66b 100644 --- a/pkg/agent/sysadvisor/test/sysadvisor_test.go +++ b/pkg/agent/sysadvisor/test/sysadvisor_test.go @@ -173,7 +173,10 @@ func TestPlugins(t *testing.T) { metaServer.PodFetcher = &pod.PodFetcherStub{} for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + metaCache, err := metacache.NewMetaCacheImp(conf, metricspool.DummyMetricsEmitterPool{}, fakeMetricsFetcher) assert.NoError(t, err) assert.NotNil(t, metaCache) diff --git a/pkg/client/control/node_test.go b/pkg/client/control/node_test.go index 617f44aa7..f8e988956 100644 --- a/pkg/client/control/node_test.go +++ b/pkg/client/control/node_test.go @@ -81,7 +81,10 @@ func TestRealNodeUpdater_PatchNodeStatus(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + baseCtx, err := katalystbase.GenerateFakeGenericContext([]runtime.Object{tt.fields.oldNode}) assert.NoError(t, err) r := NewRealNodeUpdater(baseCtx.Client.KubeClient) @@ -153,7 +156,10 @@ func TestRealNodeUpdater_PatchNode(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + baseCtx, err := katalystbase.GenerateFakeGenericContext([]runtime.Object{tt.fields.oldNode}) assert.NoError(t, err) r := NewRealNodeUpdater(baseCtx.Client.KubeClient) @@ -226,7 +232,10 @@ func TestRealNodeUpdater_UpdateNode(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + baseCtx, err := katalystbase.GenerateFakeGenericContext([]runtime.Object{tt.fields.oldNode}) assert.NoError(t, err) r := NewRealNodeUpdater(baseCtx.Client.KubeClient) diff --git a/pkg/client/control/unstructured_test.go b/pkg/client/control/unstructured_test.go index 2529b7e05..653fb751e 100644 --- a/pkg/client/control/unstructured_test.go +++ b/pkg/client/control/unstructured_test.go @@ -93,7 +93,10 @@ func Test_prepareUnstructuredPatchBytes(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got, err := prepareUnstructuredPatchBytes(tt.args.oldObj, tt.args.newObj) if !tt.wantErr(t, err, fmt.Sprintf("prepareUnstructuredPatchBytes(%v, %v)", tt.args.oldObj, tt.args.newObj)) { return @@ -141,7 +144,10 @@ func Test_prepareUnstructuredStatusPatchBytes(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got, err := prepareUnstructuredStatusPatchBytes(tt.args.oldObj, tt.args.newObj) if !tt.wantErr(t, err, fmt.Sprintf("prepareUnstructuredStatusPatchBytes(%v, %v)", tt.args.oldObj, tt.args.newObj)) { return diff --git a/pkg/client/control/vpa_test.go b/pkg/client/control/vpa_test.go index 6e1585f24..a8288ef92 100644 --- a/pkg/client/control/vpa_test.go +++ b/pkg/client/control/vpa_test.go @@ -62,7 +62,10 @@ func TestPatchVPA(t *testing.T) { newVPA: oldvpa1, }, } { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() + internalClient := externalfake.NewSimpleClientset(tc.oldVPA) updater := NewRealVPAUpdater(internalClient) _, err := updater.PatchVPA(context.TODO(), tc.oldVPA, tc.newVPA) @@ -114,7 +117,10 @@ func TestPatchVPAStatus(t *testing.T) { newVPA: oldvpa1, }, } { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() + internalClient := externalfake.NewSimpleClientset(tc.oldVPA) updater := NewRealVPAUpdater(internalClient) _, err := updater.PatchVPAStatus(context.TODO(), tc.oldVPA, tc.newVPA) diff --git a/pkg/client/control/vparec_test.go b/pkg/client/control/vparec_test.go index e3c1094fe..7caba6e34 100644 --- a/pkg/client/control/vparec_test.go +++ b/pkg/client/control/vparec_test.go @@ -62,7 +62,10 @@ func TestPatchVPARec(t *testing.T) { newVPARec: oldvparec1, }, } { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() + internalClient := externalfake.NewSimpleClientset(tc.oldVPARec) updater := NewRealVPARecommendationUpdater(internalClient) err := updater.PatchVPARecommendation(context.TODO(), tc.oldVPARec, tc.newVPARec) @@ -114,7 +117,10 @@ func TestPatchVPARecStatus(t *testing.T) { newVPARec: oldvparec1, }, } { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() + internalClient := externalfake.NewSimpleClientset(tc.oldVPARec) updater := NewRealVPARecommendationUpdater(internalClient) err := updater.PatchVPARecommendationStatus(context.TODO(), tc.oldVPARec, tc.newVPARec) diff --git a/pkg/controller/kcc/cnc_test.go b/pkg/controller/kcc/cnc_test.go index c3fadc738..8d2015667 100644 --- a/pkg/controller/kcc/cnc_test.go +++ b/pkg/controller/kcc/cnc_test.go @@ -114,7 +114,10 @@ func TestCustomNodeConfigController_Run(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + genericContext, err := katalyst_base.GenerateFakeGenericContext(nil, tt.args.cncAndKCCList, tt.args.kccTargetList) assert.NoError(t, err) conf := generateTestConfiguration(t) diff --git a/pkg/controller/kcc/kcc_test.go b/pkg/controller/kcc/kcc_test.go index 96c045f5c..34d035f76 100644 --- a/pkg/controller/kcc/kcc_test.go +++ b/pkg/controller/kcc/kcc_test.go @@ -297,7 +297,10 @@ func TestKatalystCustomConfigController_Run(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + genericContext, err := katalyst_base.GenerateFakeGenericContext(nil, tt.args.kccList, tt.args.kccTargetList) assert.NoError(t, err) conf := generateTestConfiguration(t) @@ -388,7 +391,10 @@ func Test_checkNodeLabelSelectorAllowedKeyList(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got, got1 := checkNodeLabelSelectorAllowedKeyList(tt.args.kcc) assert.Equalf(t, tt.want, got, "checkNodeLabelSelectorAllowedKeyList(%v)", tt.args.kcc) assert.Equalf(t, tt.want1, got1, "checkNodeLabelSelectorAllowedKeyList(%v)", tt.args.kcc) diff --git a/pkg/controller/kcc/kcct_test.go b/pkg/controller/kcc/kcct_test.go index 27e3b2d23..0c22d784f 100644 --- a/pkg/controller/kcc/kcct_test.go +++ b/pkg/controller/kcc/kcct_test.go @@ -303,7 +303,10 @@ func TestKatalystCustomConfigTargetController_Run(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + genericContext, err := katalyst_base.GenerateFakeGenericContext(nil, tt.args.kccList, tt.args.kccTargetList) assert.NoError(t, err) conf := generateTestConfiguration(t) @@ -420,7 +423,10 @@ func Test_validateLabelSelectorWithOthers(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got, _, _, err := validateLabelSelectorOverlapped(tt.args.priorityAllowedKeyListMap, tt.args.targetResource, tt.args.otherResources) if (err != nil) != tt.wantErr { t.Errorf("validateLabelSelectorOverlapped() error = %v, wantErr %v", err, tt.wantErr) @@ -488,7 +494,10 @@ func Test_validateTargetResourceNodeNamesWithOthers(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got, _, _, err := validateTargetResourceNodeNamesOverlapped(tt.args.targetResource, tt.args.otherResources) if (err != nil) != tt.wantErr { t.Errorf("validateTargetResourceNodeNamesOverlapped() error = %v, wantErr %v", err, tt.wantErr) @@ -537,7 +546,10 @@ func Test_validateTargetResourceGlobalWithOthers(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got, _, _, err := validateTargetResourceGlobalOverlapped(tt.args.targetResource, tt.args.otherResources) if (err != nil) != tt.wantErr { t.Errorf("validateTargetResourceGlobalOverlapped() error = %v, wantErr %v", err, tt.wantErr) @@ -622,7 +634,10 @@ func Test_updateTargetResourceStatus(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + if updateTargetResourceStatus(tt.args.targetResource, tt.args.isValid, tt.args.msg, tt.args.reason); !tt.equalFunc(tt.args.targetResource, tt.wantResource) { t.Errorf("updateTargetResourceStatus() = %v, want %v", tt.args.targetResource.GetGenericStatus(), tt.wantResource.GetGenericStatus()) } @@ -726,7 +741,9 @@ func Test_checkLabelSelectorOverlap(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() assert.Equalf(t, tt.want, checkLabelSelectorOverlap(tt.args.selector, tt.args.otherSelector, tt.args.keyList), "checkLabelSelectorOverlap(%v, %v, %v)", tt.args.selector, tt.args.otherSelector, tt.args.keyList) }) } diff --git a/pkg/controller/kcc/util/kcct_test.go b/pkg/controller/kcc/util/kcct_test.go index 59b328c05..fd8a056d2 100644 --- a/pkg/controller/kcc/util/kcct_test.go +++ b/pkg/controller/kcc/util/kcct_test.go @@ -192,7 +192,10 @@ func Test_findMatchedTargetConfig(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got, err := findMatchedKCCTargetConfigForNode(tt.args.cnc, tt.args.configList) if (err != nil) != tt.wantErr { t.Errorf("findMatchedKCCTargetConfigForNode() error = %v, wantErr %v", err, tt.wantErr) @@ -233,7 +236,9 @@ func TestUpdateKCCTGenericConditions(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() if got := UpdateKCCTGenericConditions(tt.args.status, tt.args.conditionType, tt.args.conditionStatus, tt.args.reason, tt.args.message); got != tt.want { t.Errorf("UpdateKCCTGenericConditions() = %v, want %v", got, tt.want) } diff --git a/pkg/controller/lifecycle/agent-healthz/healthz_controller_test.go b/pkg/controller/lifecycle/agent-healthz/healthz_controller_test.go index a0051fbdc..b2df82103 100644 --- a/pkg/controller/lifecycle/agent-healthz/healthz_controller_test.go +++ b/pkg/controller/lifecycle/agent-healthz/healthz_controller_test.go @@ -34,7 +34,6 @@ import ( "k8s.io/client-go/tools/cache" "k8s.io/klog/v2" - "github.com/kubewharf/katalyst-api/pkg/apis/config/v1alpha1" apis "github.com/kubewharf/katalyst-api/pkg/apis/node/v1alpha1" internalfake "github.com/kubewharf/katalyst-api/pkg/client/clientset/versioned/fake" "github.com/kubewharf/katalyst-api/pkg/client/informers/externalversions" @@ -44,8 +43,6 @@ import ( ) func generateTestKubeClientSet(objects []runtime.Object, internalObjects []runtime.Object) *client.GenericClientSet { - scheme := runtime.NewScheme() - utilruntime.Must(v1alpha1.AddToScheme(scheme)) return &client.GenericClientSet{ KubeClient: fake.NewSimpleClientset(objects...), InternalClient: internalfake.NewSimpleClientset(internalObjects...), @@ -151,6 +148,8 @@ func TestHealthzController(t *testing.T) { } func Test_podTransformerFunc(t *testing.T) { + t.Parallel() + type args struct { src *corev1.Pod dest *corev1.Pod @@ -205,7 +204,9 @@ func Test_podTransformerFunc(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() podTransformerFunc(tt.args.src, tt.args.dest) assert.Equal(t, tt.want, tt.args.dest) }) diff --git a/pkg/controller/lifecycle/cnc_test.go b/pkg/controller/lifecycle/cnc_test.go index 4e964569d..d3346c44b 100644 --- a/pkg/controller/lifecycle/cnc_test.go +++ b/pkg/controller/lifecycle/cnc_test.go @@ -118,7 +118,10 @@ func TestCNCLifecycle_Run(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + genericCtx, err := katalyst_base.GenerateFakeGenericContext([]runtime.Object{tt.fields.node}, []runtime.Object{tt.fields.cnc}) assert.NoError(t, err) @@ -217,7 +220,10 @@ func TestCNCLifecycle_updateOrCreateCNC(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + genericCtx, err := katalyst_base.GenerateFakeGenericContext([]runtime.Object{tt.fields.node}, []runtime.Object{tt.fields.cnc}) assert.NoError(t, err) diff --git a/pkg/controller/lifecycle/cnr_test.go b/pkg/controller/lifecycle/cnr_test.go index a87179caa..249fbaa5d 100644 --- a/pkg/controller/lifecycle/cnr_test.go +++ b/pkg/controller/lifecycle/cnr_test.go @@ -118,7 +118,10 @@ func TestCNRLifecycle_Run(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + genericCtx, err := katalyst_base.GenerateFakeGenericContext([]runtime.Object{tt.fields.node}, []runtime.Object{tt.fields.cnr}) assert.NoError(t, err) @@ -217,7 +220,10 @@ func TestCNRLifecycle_updateOrCreateCNR(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + genericCtx, err := katalyst_base.GenerateFakeGenericContext([]runtime.Object{tt.fields.node}, []runtime.Object{tt.fields.cnr}) assert.NoError(t, err) diff --git a/pkg/controller/monitor/cnr_indicator_test.go b/pkg/controller/monitor/cnr_indicator_test.go index 61858827b..ed0269b47 100644 --- a/pkg/controller/monitor/cnr_indicator_test.go +++ b/pkg/controller/monitor/cnr_indicator_test.go @@ -310,7 +310,11 @@ func Test_checkNumaExclusiveAnomaly(t *testing.T) { }, } for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + genericCtx, err := katalyst_base.GenerateFakeGenericContext([]runtime.Object{tt.fields.pods[0], tt.fields.pods[1]}, []runtime.Object{tt.fields.cnr}) assert.NoError(t, err) @@ -494,7 +498,10 @@ func Test_checkNumaAllocatableSumAnomaly(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + genericCtx, err := katalyst_base.GenerateFakeGenericContext([]runtime.Object{tt.fields.node}, []runtime.Object{tt.fields.cnr}) assert.NoError(t, err) @@ -671,7 +678,10 @@ func Test_checkPodAllocationSumAnomaly(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + genericCtx, err := katalyst_base.GenerateFakeGenericContext([]runtime.Object{tt.fields.pods[0]}, []runtime.Object{tt.fields.cnr}) assert.NoError(t, err) diff --git a/pkg/controller/monitor/cnr_test.go b/pkg/controller/monitor/cnr_test.go index 4b89593ee..6fe8b35f7 100644 --- a/pkg/controller/monitor/cnr_test.go +++ b/pkg/controller/monitor/cnr_test.go @@ -84,7 +84,10 @@ func TestCNRMonitor_Run(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + genericCtx, err := katalyst_base.GenerateFakeGenericContext([]runtime.Object{oldPod}, []runtime.Object{tt.fields.cnr}) assert.NoError(t, err) @@ -201,7 +204,10 @@ func Test_gcPodTimeMap(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + genericCtx, err := katalyst_base.GenerateFakeGenericContext([]runtime.Object{tt.args.pod}, []runtime.Object{}) assert.NoError(t, err) diff --git a/pkg/controller/overcommit/node/matcher/matcher_test.go b/pkg/controller/overcommit/node/matcher/matcher_test.go index 9004ebcdd..bbb70ca9f 100644 --- a/pkg/controller/overcommit/node/matcher/matcher_test.go +++ b/pkg/controller/overcommit/node/matcher/matcher_test.go @@ -156,7 +156,10 @@ func TestMatchConfigNameToNodes(t *testing.T) { matcher := makeTestMatcher() for _, tc := range testCases { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() + out, err := matcher.matchConfigNameToNodes(tc.configName) assert.Nil(t, err) assert.Equal(t, len(tc.result), len(out)) @@ -166,6 +169,7 @@ func TestMatchConfigNameToNodes(t *testing.T) { func TestMatchConfig(t *testing.T) { t.Parallel() + nodeIndexer1 := testNodeIndexer() nocIndexer1 := testNocIndexer() matcher1 := makeMatcherByIndexer(nodeIndexer1, nocIndexer1) @@ -240,7 +244,10 @@ func TestMatchConfig(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() + out, err := tc.matcher.MatchConfig(tc.configName) assert.Nil(t, err) sort.Strings(out) @@ -410,7 +417,10 @@ func TestMatchNode(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() + if tc.configName == "" { for _, c := range []string{"config1", "config2"} { _, _ = tc.matcher.MatchConfig(c) @@ -458,7 +468,10 @@ func TestDelNode(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() + tc.matcher.DelNode(tc.nodeName) fmt.Printf("testCase: %v", tc) assert.Equal(t, tc.result, len(tc.matcher.nodeToConfig)) @@ -495,7 +508,9 @@ func TestSort(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() sort.Sort(tc.nocList) assert.Equal(t, tc.result, tc.nocList[0].Name) }) diff --git a/pkg/controller/overcommit/node/node_test.go b/pkg/controller/overcommit/node/node_test.go index cb6bf52a4..0f0bc95c0 100644 --- a/pkg/controller/overcommit/node/node_test.go +++ b/pkg/controller/overcommit/node/node_test.go @@ -193,7 +193,9 @@ func TestReconcile(t *testing.T) { t.Parallel() for _, tc := range testCases { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() fss := &cliflag.NamedFlagSets{} nocOptions := options.NewOvercommitOptions() @@ -271,7 +273,10 @@ func TestRun(t *testing.T) { t.Parallel() for _, tc := range testCases { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() + fss := &cliflag.NamedFlagSets{} nocOptions := options.NewOvercommitOptions() nocOptions.AddFlags(fss) diff --git a/pkg/controller/spd/spd_baseline_test.go b/pkg/controller/spd/spd_baseline_test.go index 8b581337c..6f6adf976 100644 --- a/pkg/controller/spd/spd_baseline_test.go +++ b/pkg/controller/spd/spd_baseline_test.go @@ -562,7 +562,10 @@ func TestSPDController_updateBaselinePercentile(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + spdConfig := &controller.SPDConfig{ SPDWorkloadGVResources: []string{"statefulsets.v1.apps"}, } diff --git a/pkg/controller/spd/spd_test.go b/pkg/controller/spd/spd_test.go index ac70770ca..996a319a7 100644 --- a/pkg/controller/spd/spd_test.go +++ b/pkg/controller/spd/spd_test.go @@ -385,7 +385,9 @@ func TestSPDController_Run(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() spdConfig := &controller.SPDConfig{ SPDWorkloadGVResources: []string{"statefulsets.v1.apps"}, BaselinePercent: map[string]int64{ diff --git a/pkg/controller/tide/tide_test.go b/pkg/controller/tide/tide_test.go index 170748063..432265c49 100644 --- a/pkg/controller/tide/tide_test.go +++ b/pkg/controller/tide/tide_test.go @@ -36,6 +36,8 @@ import ( ) func TestTide_RunOnce(t1 *testing.T) { + t1.Parallel() + nodePool := &v1alpha12.TideNodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "np1", @@ -88,7 +90,10 @@ func TestTide_RunOnce(t1 *testing.T) { }, } for _, tt := range tests { + tt := tt t1.Run(tt.name, func(t1 *testing.T) { + t1.Parallel() + controlCtx, err := katalystbase.GenerateFakeGenericContext(append(tt.args.nodeList, tt.args.podList...)) if err != nil { t1.Error(err) @@ -241,6 +246,8 @@ func buildOnlinePod(nodePool NodePoolWrapper, name string, cpu int64, mem int64) } func TestTide_Reconcile(t1 *testing.T) { + t1.Parallel() + nodeReserve := intstr.FromString("30%") nodePool := &v1alpha12.TideNodePool{ ObjectMeta: metav1.ObjectMeta{ @@ -289,7 +296,10 @@ func TestTide_Reconcile(t1 *testing.T) { }, } for _, tt := range tests { + tt := tt t1.Run(tt.name, func(t1 *testing.T) { + t1.Parallel() + controlCtx, err := katalystbase.GenerateFakeGenericContext(append(tt.args.nodeList, tt.args.podList...), []runtime.Object{tt.args.tideNodePool}) if err != nil { t1.Error(err) diff --git a/pkg/controller/vpa/algorithm/recommenders/avg_load_to_cpu_test.go b/pkg/controller/vpa/algorithm/recommenders/avg_load_to_cpu_test.go index 9925f8ece..f28cc599d 100644 --- a/pkg/controller/vpa/algorithm/recommenders/avg_load_to_cpu_test.go +++ b/pkg/controller/vpa/algorithm/recommenders/avg_load_to_cpu_test.go @@ -103,7 +103,10 @@ func TestGetRecommendedPodResources(t *testing.T) { }, }, } { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() + r := NewCPURecommender() _, recommendedResources, err := r.GetRecommendedPodResources(tc.spd, []*corev1.Pod{}) assert.Equal(t, tc.want.recommendedResources, recommendedResources) diff --git a/pkg/controller/vpa/recommend_test.go b/pkg/controller/vpa/recommend_test.go index eeaa86bd3..173ccfde1 100644 --- a/pkg/controller/vpa/recommend_test.go +++ b/pkg/controller/vpa/recommend_test.go @@ -106,7 +106,10 @@ func TestResourceRecommendController_Run(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + ctx := context.TODO() genericConf := &generic.GenericConfiguration{} controllerConf := &controller.GenericControllerConfiguration{ diff --git a/pkg/controller/vpa/util/api_test.go b/pkg/controller/vpa/util/api_test.go index b1699a977..ebbf9f0e6 100644 --- a/pkg/controller/vpa/util/api_test.go +++ b/pkg/controller/vpa/util/api_test.go @@ -101,7 +101,10 @@ func TestUpdateVPAConditions(t *testing.T) { newvpa: newvpa2, }, } { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() + vpa := tc.oldvpa.DeepCopy() err := SetVPAConditions(vpa, tc.conditionType, tc.conditionStatus, "", "") assert.NoError(t, err) @@ -174,7 +177,10 @@ func TestUpdateAPIVPAConditions(t *testing.T) { newvpa: newvpa11, }, } { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() + InternalClient := externalfake.NewSimpleClientset() vpaUpdater := control.NewRealVPAUpdater(InternalClient) _, err := InternalClient.AutoscalingV1alpha1().KatalystVerticalPodAutoscalers(tc.oldvpa.Namespace).Create(context.TODO(), tc.oldvpa, metav1.CreateOptions{}) @@ -229,20 +235,23 @@ func TestUpdateVPARecConditions(t *testing.T) { }{ { name: "force update time", - oldvparec: oldvparec1, + oldvparec: oldvparec1.DeepCopy(), conditionType: apis.RecommendationUpdatedToVPA, forceUpdateTime: true, - newvparec: newvparec1, + newvparec: newvparec1.DeepCopy(), }, { name: "not force update time", - oldvparec: newvparec1, + oldvparec: newvparec1.DeepCopy(), conditionType: apis.RecommendationUpdatedToVPA, forceUpdateTime: false, - newvparec: newvparec1, + newvparec: newvparec1.DeepCopy(), }, } { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() + vparec := tc.oldvparec.DeepCopy() err := SetVPARecConditions(vparec, tc.conditionType, "", "", "") assert.NoError(t, err) diff --git a/pkg/controller/vpa/util/resource_test.go b/pkg/controller/vpa/util/resource_test.go index 64c3c4230..081bb5e2a 100644 --- a/pkg/controller/vpa/util/resource_test.go +++ b/pkg/controller/vpa/util/resource_test.go @@ -47,6 +47,8 @@ var ( ) func TestGetVPAResourceStatusWithCurrent(t *testing.T) { + t.Parallel() + // test with no indexers klog.Infof("================== test with no indexers ==================") testGetVPAResourceStatusWithCurrentAndIndexer(t, nil, []string{}) @@ -475,6 +477,8 @@ func testGetVPAResourceStatusWithCurrentAndIndexer(t *testing.T, podIndexers cac } func TestGetVPAResourceStatusWithRecommendation(t *testing.T) { + t.Parallel() + type args struct { vpa *apis.KatalystVerticalPodAutoscaler recPodResources []apis.RecommendedPodResources @@ -634,7 +638,9 @@ func TestGetVPAResourceStatusWithRecommendation(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() got, got1, err := GetVPAResourceStatusWithRecommendation(tt.args.vpa, tt.args.recPodResources, tt.args.recContainerResources) if !tt.wantErr(t, err, fmt.Sprintf("GetVPAResourceStatusWithRecommendation(%v, %v, %v)", tt.args.vpa, tt.args.recPodResources, tt.args.recContainerResources)) { return diff --git a/pkg/controller/vpa/vpa_test.go b/pkg/controller/vpa/vpa_test.go index eafcefa51..9dd7b04f6 100644 --- a/pkg/controller/vpa/vpa_test.go +++ b/pkg/controller/vpa/vpa_test.go @@ -338,7 +338,10 @@ func TestVPAControllerSyncVPA(t *testing.T) { }, }, } { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() + fss := &cliflag.NamedFlagSets{} vpaOptions := options.NewVPAOptions() vpaOptions.AddFlags(fss) @@ -501,7 +504,10 @@ func TestVPAControllerSyncPod(t *testing.T) { newPod: newPod1, }, } { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() + fss := &cliflag.NamedFlagSets{} vpaOptions := options.NewVPAOptions() vpaOptions.AddFlags(fss) @@ -664,7 +670,10 @@ func TestVPAControllerSyncWorkload(t *testing.T) { newPod: newPod1, }, } { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() + fss := &cliflag.NamedFlagSets{} vpaOptions := options.NewVPAOptions() vpaOptions.AddFlags(fss) diff --git a/pkg/controller/vpa/vparec_test.go b/pkg/controller/vpa/vparec_test.go index 270636587..3fe73e8f6 100644 --- a/pkg/controller/vpa/vparec_test.go +++ b/pkg/controller/vpa/vparec_test.go @@ -302,7 +302,10 @@ func TestVPARecControllerSyncVPA(t *testing.T) { }, }, } { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() + genericConfig := &generic.GenericConfiguration{} controllerConf := &controller.GenericControllerConfiguration{ DynamicGVResources: []string{"statefulsets.v1.apps"}, @@ -491,7 +494,10 @@ func TestVPARecControllerSyncVPARec(t *testing.T) { }, }, } { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() + genericConfig := &generic.GenericConfiguration{} controllerConf := &controller.GenericControllerConfiguration{ DynamicGVResources: []string{"statefulsets.v1.apps"}, diff --git a/pkg/custom-metric/store/data/cache_test.go b/pkg/custom-metric/store/data/cache_test.go index 88aac9056..230e733a5 100644 --- a/pkg/custom-metric/store/data/cache_test.go +++ b/pkg/custom-metric/store/data/cache_test.go @@ -740,7 +740,9 @@ func TestMergeInternalMetricList(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() got := MergeInternalMetricList(tt.args.metricName, tt.args.metricLists...) assert.Equalf(t, tt.want, got, "MergeInternalMetricList(%v, %v)", tt.args.metricName, tt.args.metricLists) }) diff --git a/pkg/metaserver/agent/metric/metric_expire_test.go b/pkg/metaserver/agent/metric/metric_expire_test.go index 052875199..f5a9a5bee 100644 --- a/pkg/metaserver/agent/metric/metric_expire_test.go +++ b/pkg/metaserver/agent/metric/metric_expire_test.go @@ -27,6 +27,8 @@ import ( ) func TestMetricExpire(t *testing.T) { + t.Parallel() + updateTime := time.Now().Add(-65 * time.Second) metricData := utilmetric.MetricData{ Time: &updateTime, diff --git a/pkg/metaserver/agent/metric/provisioner/malachite/client/client_pod_test.go b/pkg/metaserver/agent/metric/provisioner/malachite/client/client_pod_test.go index b8efcd71e..a74de0557 100644 --- a/pkg/metaserver/agent/metric/provisioner/malachite/client/client_pod_test.go +++ b/pkg/metaserver/agent/metric/provisioner/malachite/client/client_pod_test.go @@ -36,6 +36,8 @@ import ( ) func TestGetPodContainerStats(t *testing.T) { + t.Parallel() + cgroupData := map[string]*types.MalachiteCgroupResponse{ "podp-uid1/p1-c-uid1": { Status: 0, diff --git a/pkg/metaserver/agent/pod/pod_test.go b/pkg/metaserver/agent/pod/pod_test.go index bbf3d8c3c..eb836a3c7 100644 --- a/pkg/metaserver/agent/pod/pod_test.go +++ b/pkg/metaserver/agent/pod/pod_test.go @@ -23,35 +23,29 @@ import ( "github.com/kubewharf/katalyst-core/pkg/util/cgroup/common" ) -func Test_getDefaultAbsCgroupRootPaths(t *testing.T) { - name := "test for cgroupfs" +func Test_getCgroupRootPaths(t *testing.T) { + t.Parallel() + want := []string{ "/sys/fs/cgroup/cpu/kubepods", "/sys/fs/cgroup/cpu/kubepods/besteffort", "/sys/fs/cgroup/cpu/kubepods/burstable", } - t.Run(name, func(t *testing.T) { - if got := common.GetKubernetesCgroupRootPathWithSubSys("cpu"); !reflect.DeepEqual(got, want) { - t.Errorf("getAbsCgroupRootPaths() \n got = %v, \n want = %v\n", got, want) - } - }) -} + if got := common.GetKubernetesCgroupRootPathWithSubSys("cpu"); !reflect.DeepEqual(got, want) { + t.Errorf("getAbsCgroupRootPaths() \n got = %v, \n want = %v\n", got, want) + } -func Test_getAdditionAbsCgroupRootPaths(t *testing.T) { common.InitKubernetesCGroupPath(common.CgroupTypeSystemd, []string{"/kubepods/test.slice"}) - name := "test for cgroupfs" - want := []string{ + want = []string{ "/sys/fs/cgroup/cpu/kubepods.slice", "/sys/fs/cgroup/cpu/kubepods.slice/kubepods-besteffort.slice", "/sys/fs/cgroup/cpu/kubepods.slice/kubepods-burstable.slice", "/sys/fs/cgroup/cpu/kubepods/test.slice", } - t.Run(name, func(t *testing.T) { - if got := common.GetKubernetesCgroupRootPathWithSubSys("cpu"); !reflect.DeepEqual(got, want) { - t.Errorf("getAbsCgroupRootPaths() \n got = %v, \n want = %v\n", got, want) - } - }) + if got := common.GetKubernetesCgroupRootPathWithSubSys("cpu"); !reflect.DeepEqual(got, want) { + t.Errorf("getAbsCgroupRootPaths() \n got = %v, \n want = %v\n", got, want) + } } diff --git a/pkg/metaserver/external/cgroupid/manager_linux_test.go b/pkg/metaserver/external/cgroupid/manager_linux_test.go index a46d292d7..06c0aad14 100644 --- a/pkg/metaserver/external/cgroupid/manager_linux_test.go +++ b/pkg/metaserver/external/cgroupid/manager_linux_test.go @@ -72,7 +72,9 @@ func TestGetCgroupIDForContainer(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() cgID, err := cgroupIDManager.GetCgroupIDForContainer(tt.podUID, tt.containerID) assert.NoError(t, err) assert.Equal(t, tt.want, cgID) @@ -108,7 +110,10 @@ func TestListCgroupIDsForPod(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + cgIDs, err := cgroupIDManager.ListCgroupIDsForPod(tt.podUID) assert.NoError(t, err) sort.Slice(tt.want, func(i, j int) bool { return tt.want[i] < tt.want[j] }) @@ -144,7 +149,10 @@ func TestGetAbsentContainers(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + gotAbsentContainers := cgroupIDManager.getAbsentContainers(tt.podList) assert.Equal(t, len(tt.want), len(gotAbsentContainers)) for wantPodUID, wantContainerSet := range tt.want { @@ -188,7 +196,9 @@ func TestClearResidualPodsInCache(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() for i := 0; time.Duration(i)*cgroupIDManager.reconcilePeriod < maxResidualTime; i++ { cgroupIDManager.clearResidualPodsInCache(tt.podList) } diff --git a/pkg/metaserver/kcc/config_test.go b/pkg/metaserver/kcc/config_test.go index 3822a6160..06056b19d 100644 --- a/pkg/metaserver/kcc/config_test.go +++ b/pkg/metaserver/kcc/config_test.go @@ -120,7 +120,9 @@ func Test_katalystCustomConfigLoader_LoadConfig(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() c := constructKatalystCustomConfigLoader() if err := c.LoadConfig(tt.args.ctx, tt.args.gvr, tt.args.conf); (err != nil) != tt.wantErr { t.Errorf("LoadConfig() error = %v, wantErr %v", err, tt.wantErr) diff --git a/pkg/metaserver/kcc/manager_test.go b/pkg/metaserver/kcc/manager_test.go index 1db7940e4..b58ba8b5d 100644 --- a/pkg/metaserver/kcc/manager_test.go +++ b/pkg/metaserver/kcc/manager_test.go @@ -232,7 +232,10 @@ func TestDynamicConfigManager_getConfig(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + c := tt.fields.manager defer os.RemoveAll(c.conf.CheckpointManagerDir) err := c.updateConfig(tt.args.ctx) @@ -352,7 +355,9 @@ func Test_applyDynamicConfig(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() applyDynamicConfig(tt.args.currentConfig, tt.args.dynamicConf) got := tt.args.currentConfig require.True(t, tt.want(got)) @@ -380,7 +385,9 @@ func Test_getGVRToKindMap(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() if got := getGVRToGVKMap(); !checkGVRToGVKMap(tt.wantGVR, tt.wantGVK, got) { t.Errorf("getGVRToGVKMap() = %v, wantGVR %v wantGVK %v", got, tt.wantGVR, tt.wantGVK) } @@ -463,7 +470,10 @@ func Test_updateDynamicConf(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + ec := generateTestEvictionConfiguration(map[v1.ResourceName]float64{ v1.ResourceCPU: 1.2, v1.ResourceMemory: 1.3, diff --git a/pkg/metaserver/spd/fetcher_test.go b/pkg/metaserver/spd/fetcher_test.go index 51ad10482..f9787d773 100644 --- a/pkg/metaserver/spd/fetcher_test.go +++ b/pkg/metaserver/spd/fetcher_test.go @@ -40,8 +40,6 @@ import ( ) func generateTestConfiguration(t *testing.T, nodeName string, checkpoint string) *pkgconfig.Configuration { - t.Parallel() - testConfiguration, err := options.NewOptions().Config() require.NoError(t, err) require.NotNil(t, testConfiguration) @@ -183,7 +181,10 @@ func Test_spdManager_GetSPD(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + dir, err := ioutil.TempDir("", "checkpoint-Test_spdManager_GetSPD") require.NoError(t, err) defer os.RemoveAll(dir) diff --git a/pkg/metaserver/spd/manager_test.go b/pkg/metaserver/spd/manager_test.go index 88a989d3b..c1723d93d 100644 --- a/pkg/metaserver/spd/manager_test.go +++ b/pkg/metaserver/spd/manager_test.go @@ -19,6 +19,7 @@ package spd import ( "context" "encoding/json" + "fmt" "io/ioutil" "os" "testing" @@ -250,7 +251,10 @@ func Test_serviceProfilingManager_ServiceBusinessPerformanceLevel(t *testing.T) }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + dir, err := ioutil.TempDir("", "checkpoint-Test_serviceProfilingManager_ServiceBusinessPerformanceLevel") require.NoError(t, err) defer os.RemoveAll(dir) @@ -386,9 +390,13 @@ func Test_serviceProfilingManager_ServiceSystemPerformanceTarget(t *testing.T) { }, }, } - for _, tt := range tests { + for i, tt := range tests { + i := i + tt := tt t.Run(tt.name, func(t *testing.T) { - dir, err := ioutil.TempDir("", "checkpoint-Test_serviceProfilingManager_ServiceSystemPerformanceTarget") + t.Parallel() + + dir, err := ioutil.TempDir("", fmt.Sprintf("checkpoint-Test_serviceProfilingManager_ServiceSystemPerformanceTarget_%d", i)) require.NoError(t, err) defer os.RemoveAll(dir) @@ -623,7 +631,9 @@ func Test_serviceProfilingManager_ServiceExtendedIndicator(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() dir, err := ioutil.TempDir("", "checkpoint-Test_serviceProfilingManager_ServiceExtendedIndicator") require.NoError(t, err) defer os.RemoveAll(dir) @@ -770,7 +780,10 @@ func Test_serviceProfilingManager_ServiceBaseline(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + dir, err := ioutil.TempDir("", "checkpoint-Test_serviceProfilingManager_ServiceBaseline") require.NoError(t, err) defer os.RemoveAll(dir) diff --git a/pkg/metaserver/spd/util_test.go b/pkg/metaserver/spd/util_test.go index c5c6af7dd..dab93e906 100644 --- a/pkg/metaserver/spd/util_test.go +++ b/pkg/metaserver/spd/util_test.go @@ -103,7 +103,9 @@ func TestGetContainerMemoryBandwidthRequest(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() got, err := GetContainerMemoryBandwidthRequest(tt.args.profilingManager, tt.args.podMeta, tt.args.cpuRequest) if (err != nil) != tt.wantErr { t.Errorf("GetContainerMemoryBandwidthRequest() error = %v, wantErr %v", err, tt.wantErr) diff --git a/pkg/util/bitmask/bitmask_test.go b/pkg/util/bitmask/bitmask_test.go index b4d6531ef..f4257198a 100644 --- a/pkg/util/bitmask/bitmask_test.go +++ b/pkg/util/bitmask/bitmask_test.go @@ -22,6 +22,8 @@ import ( ) func TestNewEmptyiBitMask(t *testing.T) { + t.Parallel() + tcases := []struct { name string expectedMask string @@ -40,6 +42,8 @@ func TestNewEmptyiBitMask(t *testing.T) { } func TestNewBitMask(t *testing.T) { + t.Parallel() + tcases := []struct { name string bits []int @@ -70,6 +74,8 @@ func TestNewBitMask(t *testing.T) { } func TestAdd(t *testing.T) { + t.Parallel() + tcases := []struct { name string bits []int @@ -106,6 +112,8 @@ func TestAdd(t *testing.T) { } func TestRemove(t *testing.T) { + t.Parallel() + tcases := []struct { name string bitsSet []int @@ -147,6 +155,8 @@ func TestRemove(t *testing.T) { } func TestAnd(t *testing.T) { + t.Parallel() + tcases := []struct { name string masks [][]int @@ -198,6 +208,8 @@ func TestAnd(t *testing.T) { } func TestOr(t *testing.T) { + t.Parallel() + tcases := []struct { name string masks [][]int @@ -248,6 +260,8 @@ func TestOr(t *testing.T) { } func TestClear(t *testing.T) { + t.Parallel() + tcases := []struct { name string mask []int @@ -279,6 +293,8 @@ func TestClear(t *testing.T) { } func TestFill(t *testing.T) { + t.Parallel() + tcases := []struct { name string mask []int @@ -310,6 +326,8 @@ func TestFill(t *testing.T) { } func TestIsEmpty(t *testing.T) { + t.Parallel() + tcases := []struct { name string mask []int @@ -341,6 +359,8 @@ func TestIsEmpty(t *testing.T) { } func TestIsSet(t *testing.T) { + t.Parallel() + tcases := []struct { name string mask []int @@ -382,6 +402,8 @@ func TestIsSet(t *testing.T) { } func TestAnySet(t *testing.T) { + t.Parallel() + tcases := []struct { name string mask []int @@ -429,6 +451,8 @@ func TestAnySet(t *testing.T) { } func TestIsEqual(t *testing.T) { + t.Parallel() + tcases := []struct { name string firstMask []int @@ -477,6 +501,8 @@ func TestIsEqual(t *testing.T) { } func TestCount(t *testing.T) { + t.Parallel() + tcases := []struct { name string bits []int @@ -508,6 +534,8 @@ func TestCount(t *testing.T) { } func TestGetBits(t *testing.T) { + t.Parallel() + tcases := []struct { name string bits []int @@ -539,6 +567,8 @@ func TestGetBits(t *testing.T) { } func TestIsNarrowerThan(t *testing.T) { + t.Parallel() + tcases := []struct { name string firstMask []int @@ -581,6 +611,8 @@ func TestIsNarrowerThan(t *testing.T) { } func TestIterateBitMasks(t *testing.T) { + t.Parallel() + tcases := []struct { name string numbits int diff --git a/pkg/util/cgroup/manager/v1/fs_linux_test.go b/pkg/util/cgroup/manager/v1/fs_linux_test.go index 9b66362ed..dbb25f989 100644 --- a/pkg/util/cgroup/manager/v1/fs_linux_test.go +++ b/pkg/util/cgroup/manager/v1/fs_linux_test.go @@ -39,7 +39,9 @@ func TestNewManager(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() if got := NewManager(); !reflect.DeepEqual(got, tt.want) { t.Errorf("NewManager() = %v, want %v", got, tt.want) } @@ -84,7 +86,10 @@ func Test_manager_ApplyMemory(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + m := &manager{} if err := m.ApplyMemory(tt.args.absCgroupPath, tt.args.data); (err != nil) != tt.wantErr { t.Errorf("manager.ApplyMemory() error = %v, wantErr %v", err, tt.wantErr) diff --git a/pkg/util/cgroup/manager/v2/fs_linux_test.go b/pkg/util/cgroup/manager/v2/fs_linux_test.go index 1f9389429..0a9fad9d2 100644 --- a/pkg/util/cgroup/manager/v2/fs_linux_test.go +++ b/pkg/util/cgroup/manager/v2/fs_linux_test.go @@ -39,7 +39,10 @@ func TestNewManager(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + if got := NewManager(); !reflect.DeepEqual(got, tt.want) { t.Errorf("NewManager() = %v, want %v", got, tt.want) } @@ -95,7 +98,9 @@ func Test_manager_ApplyMemory(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() m := &manager{} if err := m.ApplyMemory(tt.args.absCgroupPath, tt.args.data); (err != nil) != tt.wantErr { t.Errorf("manager.ApplyMemory() error = %v, wantErr %v", err, tt.wantErr) @@ -130,7 +135,10 @@ func Test_manager_ApplyCPU(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + m := &manager{} if err := m.ApplyCPU(tt.args.absCgroupPath, tt.args.data); (err != nil) != tt.wantErr { t.Errorf("manager.ApplyCPU() error = %v, wantErr %v", err, tt.wantErr) @@ -165,7 +173,10 @@ func Test_manager_ApplyCPUSet(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + m := &manager{} if err := m.ApplyCPUSet(tt.args.absCgroupPath, tt.args.data); (err != nil) != tt.wantErr { t.Errorf("manager.ApplyCPUSet() error = %v, wantErr %v", err, tt.wantErr) @@ -199,7 +210,10 @@ func Test_manager_ApplyNetCls(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + m := &manager{} if err := m.ApplyNetCls(tt.args.in0, tt.args.in1); (err != nil) != tt.wantErr { t.Errorf("manager.ApplyNetCls() error = %v, wantErr %v", err, tt.wantErr) @@ -246,7 +260,10 @@ func Test_manager_ApplyIOCostQoS(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + m := &manager{} if err := m.ApplyIOCostQoS(tt.args.absCgroupPath, tt.args.devID, tt.args.data); (err != nil) != tt.wantErr { t.Errorf("manager.ApplyIOCostQoS() error = %v, wantErr %v", err, tt.wantErr) @@ -293,7 +310,10 @@ func Test_manager_ApplyIOCostModel(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + m := &manager{} if err := m.ApplyIOCostModel(tt.args.absCgroupPath, tt.args.devID, tt.args.data); (err != nil) != tt.wantErr { t.Errorf("manager.ApplyIOCostModel() error = %v, wantErr %v", err, tt.wantErr) @@ -328,7 +348,10 @@ func Test_manager_ApplyIOWeight(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + m := &manager{} if err := m.ApplyIOWeight(tt.args.absCgroupPath, tt.args.devID, tt.args.weight); (err != nil) != tt.wantErr { t.Errorf("manager.ApplyIOWeight() error = %v, wantErr %v", err, tt.wantErr) @@ -363,7 +386,10 @@ func Test_manager_ApplyUnifiedData(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + m := &manager{} if err := m.ApplyUnifiedData(tt.args.absCgroupPath, tt.args.cgroupFileName, tt.args.data); (err != nil) != tt.wantErr { t.Errorf("manager.ApplyUnifiedData() error = %v, wantErr %v", err, tt.wantErr) @@ -396,7 +422,10 @@ func Test_manager_GetMemory(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + m := &manager{} got, err := m.GetMemory(tt.args.absCgroupPath) if (err != nil) != tt.wantErr { @@ -434,7 +463,10 @@ func Test_manager_GetCPUSet(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + m := &manager{} got, err := m.GetCPUSet(tt.args.absCgroupPath) if (err != nil) != tt.wantErr { @@ -472,7 +504,10 @@ func Test_manager_GetCPU(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + m := &manager{} got, err := m.GetCPU(tt.args.absCgroupPath) if (err != nil) != tt.wantErr { @@ -510,7 +545,10 @@ func Test_manager_GetIOCostQoS(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + m := &manager{} got, err := m.GetIOCostQoS(tt.args.absCgroupPath) if (err != nil) != tt.wantErr { @@ -548,7 +586,10 @@ func Test_manager_GetIOCostModel(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + m := &manager{} got, err := m.GetIOCostModel(tt.args.absCgroupPath) if (err != nil) != tt.wantErr { @@ -590,7 +631,10 @@ func Test_manager_GetDeviceIOWeight(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + m := &manager{} got, got1, err := m.GetDeviceIOWeight(tt.args.absCgroupPath, tt.args.devID) if (err != nil) != tt.wantErr { @@ -631,7 +675,10 @@ func Test_manager_GetIOStat(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + m := &manager{} got, err := m.GetIOStat(tt.args.absCgroupPath) if (err != nil) != tt.wantErr { @@ -670,7 +717,10 @@ func Test_manager_GetMetrics(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + m := &manager{} got, err := m.GetMetrics(tt.args.relCgroupPath, tt.args.in1) if (err != nil) != tt.wantErr { @@ -708,7 +758,10 @@ func Test_manager_GetPids(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + m := &manager{} got, err := m.GetPids(tt.args.absCgroupPath) if (err != nil) != tt.wantErr { @@ -746,7 +799,10 @@ func Test_manager_GetTasks(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + m := &manager{} got, err := m.GetTasks(tt.args.absCgroupPath) if (err != nil) != tt.wantErr { @@ -780,7 +836,9 @@ func Test_numToStr(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() if gotRet := numToStr(tt.args.value); gotRet != tt.wantRet { t.Errorf("numToStr() = %v, want %v", gotRet, tt.wantRet) } @@ -821,7 +879,10 @@ func Test_parseDeviceIOCostQoS(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got, got1, err := parseDeviceIOCostQoS(tt.args.str) if (err != nil) != tt.wantErr { t.Errorf("parseDeviceIOCostQoS() error = %v, wantErr %v", err, tt.wantErr) @@ -870,7 +931,10 @@ func Test_parseDeviceIOCostModel(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got, got1, err := parseDeviceIOCostModel(tt.args.str) if (err != nil) != tt.wantErr { t.Errorf("parseDeviceIOCostModel() error = %v, wantErr %v", err, tt.wantErr) diff --git a/pkg/util/cnr_test.go b/pkg/util/cnr_test.go index 7e9beec5c..b1f4e3168 100644 --- a/pkg/util/cnr_test.go +++ b/pkg/util/cnr_test.go @@ -141,7 +141,9 @@ func TestAddOrUpdateCNRTaint(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() got, got1, err := AddOrUpdateCNRTaint(tt.args.cnr, tt.args.taint) if !tt.wantErr(t, err, fmt.Sprintf("AddOrUpdateCNRTaint(%v, %v)", tt.args.cnr, tt.args.taint)) { return @@ -202,7 +204,9 @@ func TestCNRTaintExists(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() assert.Equalf(t, tt.want, CNRTaintExists(tt.args.taints, tt.args.taintToFind), "CNRTaintExists(%v, %v)", tt.args.taints, tt.args.taintToFind) }) } @@ -287,7 +291,9 @@ func TestMergeAllocations(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() assert.Equalf(t, tt.want, MergeAllocations(tt.args.dst, tt.args.src), "MergeAllocations(%v, %v)", tt.args.dst, tt.args.src) }) } @@ -357,7 +363,9 @@ func TestMergeAttributes(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() assert.Equalf(t, tt.want, MergeAttributes(tt.args.dst, tt.args.src), "MergeAttributes(%v, %v)", tt.args.dst, tt.args.src) }) } @@ -404,7 +412,9 @@ func TestMergeResources(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() assert.Equalf(t, tt.want, MergeResources(tt.args.dst, tt.args.src), "MergeResources(%v, %v)", tt.args.dst, tt.args.src) }) } @@ -1420,7 +1430,9 @@ func TestMergeTopologyZone(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() expect := MergeTopologyZone(tt.args.dst, tt.args.src) assert.Equalf(t, tt.want, expect, "MergeTopologyZone(%v, %v)", tt.args.dst, tt.args.src) }) diff --git a/pkg/util/credential/authorization/dynamic_test.go b/pkg/util/credential/authorization/dynamic_test.go index c20d2789f..9f62b758b 100644 --- a/pkg/util/credential/authorization/dynamic_test.go +++ b/pkg/util/credential/authorization/dynamic_test.go @@ -94,7 +94,9 @@ func Test_dynamicConfAccessControl_Verify(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() if err := accessControl.Verify(tt.args.authInfo, tt.args.targetResource); (err != nil) != tt.wantErr { t.Errorf("Verify() error = %v, wantErr %v", err, tt.wantErr) } diff --git a/pkg/util/credential/authorization/insecure_test.go b/pkg/util/credential/authorization/insecure_test.go index 9dc2b43ef..ed4f92607 100644 --- a/pkg/util/credential/authorization/insecure_test.go +++ b/pkg/util/credential/authorization/insecure_test.go @@ -39,7 +39,9 @@ func Test_insecureAccessControl_Verify(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() i := &insecureAccessControl{} if err := i.Verify(tt.authInfo, tt.permission); (err != nil) != tt.wantErr { t.Errorf("Verify() error = %v, wantErr %v", err, tt.wantErr) diff --git a/pkg/util/credential/authorization/static_test.go b/pkg/util/credential/authorization/static_test.go index 0c1337858..4e155c7bd 100644 --- a/pkg/util/credential/authorization/static_test.go +++ b/pkg/util/credential/authorization/static_test.go @@ -63,7 +63,9 @@ func Test_staticAccessControl_Verify(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() err := s.Verify(tt.args.authInfo, tt.args.targetResource) assert.Equal(t, tt.wantErr, err != nil) }) diff --git a/pkg/util/credential/basic_test.go b/pkg/util/credential/basic_test.go index 9a584416c..eaa1f1300 100644 --- a/pkg/util/credential/basic_test.go +++ b/pkg/util/credential/basic_test.go @@ -86,7 +86,10 @@ func Test_basicAuthCredential_Auth(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + hr := &http.Request{ Header: make(http.Header), } @@ -133,7 +136,10 @@ func Test_basicAuthCredential_AuthToken(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got, err := cred.AuthToken(makeBasicToken(tt.username, tt.password)) if (err != nil) != tt.wantErr { t.Errorf("Auth() error = %v, wantErr %v", err, tt.wantErr) diff --git a/pkg/util/credential/insecure_test.go b/pkg/util/credential/insecure_test.go index ff0c689e1..8469352bd 100644 --- a/pkg/util/credential/insecure_test.go +++ b/pkg/util/credential/insecure_test.go @@ -38,7 +38,9 @@ func Test_insecureCredential_Auth(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() i := &insecureCredential{} got, err := i.Auth(&http.Request{}) assert.Equal(t, tt.want, got) @@ -62,7 +64,9 @@ func Test_insecureCredential_AuthToken(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() i := &insecureCredential{} got, err := i.AuthToken("") assert.Equal(t, tt.want, got) diff --git a/pkg/util/general/flags_test.go b/pkg/util/general/flags_test.go index ae96d08d6..55679b16f 100644 --- a/pkg/util/general/flags_test.go +++ b/pkg/util/general/flags_test.go @@ -50,7 +50,10 @@ func TestResourceList_Set(t *testing.T) { } for _, tt := range tests { r := ResourceList{} + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + err := r.Set(tt.args.value) assert.Equalf(t, tt.wantErr, err != nil, "Set(%v) return err", tt.args.value) assert.Equal(t, tt.wantResource, r) @@ -84,7 +87,9 @@ func TestResourceList_String(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() assert.Equalf(t, tt.want, tt.r.String(), "String()") }) } diff --git a/pkg/util/general/list_test.go b/pkg/util/general/list_test.go index fd358c34c..3833b74b3 100644 --- a/pkg/util/general/list_test.go +++ b/pkg/util/general/list_test.go @@ -21,6 +21,8 @@ import ( ) func TestSliceContains(t *testing.T) { + t.Parallel() + type args struct { list interface{} elem interface{} @@ -138,7 +140,9 @@ func TestSliceContains(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() if got := SliceContains(tt.args.list, tt.args.elem); got != tt.want { t.Errorf("SliceContains() = %v, want %v", got, tt.want) } diff --git a/pkg/util/general/string_test.go b/pkg/util/general/string_test.go index ceb48102b..6b3efff90 100644 --- a/pkg/util/general/string_test.go +++ b/pkg/util/general/string_test.go @@ -26,6 +26,8 @@ type struct1 struct { } func TestStructToString(t *testing.T) { + t.Parallel() + type args struct { val interface{} } @@ -46,7 +48,9 @@ func TestStructToString(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() if got := StructToString(tt.args.val); got != tt.want { t.Errorf("StructToString() = %v, want %v", got, tt.want) } diff --git a/pkg/util/general/window_test.go b/pkg/util/general/window_test.go index 5e1235711..9098fb301 100644 --- a/pkg/util/general/window_test.go +++ b/pkg/util/general/window_test.go @@ -55,7 +55,9 @@ func TestNewCappedSmoothWindow(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() NewCappedSmoothWindow(tt.args.minStep, tt.args.maxStep, tt.args.smoothWindow) }) } @@ -238,7 +240,9 @@ func TestPercentileWithTTLSmoothWindow(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() w := NewPercentileWithTTLSmoothWindow(tt.args.windowSize, tt.args.ttl, tt.args.percentile, true) for i, v := range tt.args.values { ret := w.GetWindowedResources(v) @@ -308,7 +312,10 @@ func TestWindowEmpty(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + w := NewPercentileWithTTLSmoothWindow(tt.args.windowSize, tt.args.ttl, tt.args.percentile, true) window := w.(*percentileWithTTLSmoothWindow) window.samples = tt.args.samples diff --git a/pkg/util/kcct_test.go b/pkg/util/kcct_test.go index a16b080ad..3151255cb 100644 --- a/pkg/util/kcct_test.go +++ b/pkg/util/kcct_test.go @@ -97,7 +97,10 @@ func Test_kccTargetResource_GetCollisionCount(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + g := &KCCTargetResource{ Unstructured: tt.fields.Unstructured, } @@ -141,7 +144,10 @@ func Test_kccTargetResource_GetHash(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + g := &KCCTargetResource{ Unstructured: tt.fields.Unstructured, } @@ -185,7 +191,9 @@ func Test_kccTargetResource_GetLabelSelector(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() g := &KCCTargetResource{ Unstructured: tt.fields.Unstructured, } @@ -231,7 +239,10 @@ func Test_kccTargetResource_GetLastDuration(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + g := &KCCTargetResource{ Unstructured: tt.fields.Unstructured, } @@ -283,7 +294,10 @@ func Test_kccTargetResource_GetNodeNames(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + g := &KCCTargetResource{ Unstructured: tt.fields.Unstructured, } @@ -325,7 +339,10 @@ func Test_kccTargetResource_GetObservedGeneration(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + g := &KCCTargetResource{ Unstructured: tt.fields.Unstructured, } @@ -369,7 +386,10 @@ func Test_kccTargetResource_GetRevisionHistoryLimit(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + g := &KCCTargetResource{ Unstructured: tt.fields.Unstructured, } @@ -447,7 +467,9 @@ func Test_kccTargetResource_SetCollisionCount(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() g := &KCCTargetResource{ Unstructured: tt.fields.Unstructured, } @@ -514,7 +536,9 @@ func Test_kccTargetResource_SetHash(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() g := &KCCTargetResource{ Unstructured: tt.fields.Unstructured, } @@ -575,7 +599,10 @@ func Test_kccTargetResource_SetObservedGeneration(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + g := &KCCTargetResource{ Unstructured: tt.fields.Unstructured, } @@ -633,7 +660,10 @@ func Test_kccTargetResource_GetConfig(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + g := &KCCTargetResource{ Unstructured: tt.fields.Unstructured, } @@ -684,7 +714,9 @@ func Test_kccTargetResource_GetGenericStatus(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() g := &KCCTargetResource{ Unstructured: tt.fields.Unstructured, } @@ -771,7 +803,9 @@ func Test_kccTargetResource_SetGenericStatus(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() g := &KCCTargetResource{ Unstructured: tt.fields.Unstructured, } @@ -803,7 +837,9 @@ func Test_kccTargetResource_GetIsValid(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() g := &KCCTargetResource{ Unstructured: tt.fields.Unstructured, } @@ -865,7 +901,9 @@ func Test_kccTargetResource_GenerateConfigHash(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() g := &KCCTargetResource{ Unstructured: tt.fields.Unstructured, } @@ -940,7 +978,10 @@ func TestKCCTargetResource_IsExpired(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + g := KCCTargetResource{ Unstructured: tt.fields.Unstructured, } diff --git a/pkg/util/native/pod_sorter_test.go b/pkg/util/native/pod_sorter_test.go index 2b15cf3ac..4e3abaa76 100644 --- a/pkg/util/native/pod_sorter_test.go +++ b/pkg/util/native/pod_sorter_test.go @@ -25,6 +25,8 @@ import ( ) func TestPodUniqKeyCmpFunc(t *testing.T) { + t.Parallel() + type args struct { i1 *v1.Pod i2 *v1.Pod @@ -90,7 +92,9 @@ func TestPodUniqKeyCmpFunc(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() assert.Equalf(t, tt.want, PodUniqKeyCmpFunc(tt.args.i1, tt.args.i2), "PodUniqKeyCmpFunc(%v, %v)", tt.args.i1, tt.args.i2) }) } diff --git a/pkg/util/native/pods_test.go b/pkg/util/native/pods_test.go index 555b89d91..4e14492de 100644 --- a/pkg/util/native/pods_test.go +++ b/pkg/util/native/pods_test.go @@ -57,7 +57,10 @@ func TestFilterPodAnnotations(t *testing.T) { }, }, } { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() + t.Logf("case: %v", tc.name) got := FilterPodAnnotations(tc.filterKeys, tc.pod) assert.Equal(t, tc.expected, got) @@ -100,7 +103,10 @@ func TestGetContainerID(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got, err := GetContainerID(tt.args.pod, tt.args.name) if !tt.wantErr(t, err, fmt.Sprintf("GetContainerID(%v, %v)", tt.args.pod, tt.args.name)) { return @@ -159,7 +165,10 @@ func TestGetContainerEnvs(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + assert.Equalf(t, tt.want, GetContainerEnvs(tt.args.pod, tt.args.containerName, tt.args.envs...), "GetContainerEnvs(%v, %v, %v)", tt.args.pod, tt.args.containerName, tt.args.envs) }) } @@ -203,7 +212,10 @@ func TestGetPodHostIPs(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got, _ := GetPodHostIPs(tt.args.pod) assert.Equalf(t, tt.want, got, "GetPodHostIP(%v)", tt.args.pod) }) @@ -257,13 +269,18 @@ func TestParseHostPortForPod(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got, _ := ParseHostPortForPod(tt.args.pod, "test") assert.Equalf(t, tt.want, got, "GetPodHostIP(%v)", tt.args.pod) }) } } func TestPodIsPending(t *testing.T) { + t.Parallel() + type args struct { pod *v1.Pod } @@ -301,7 +318,10 @@ func TestPodIsPending(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + if got := PodIsPending(tt.args.pod); got != tt.want { t.Errorf("PodIsPending() = %v, want %v", got, tt.want) } diff --git a/pkg/util/native/qos_resources_test.go b/pkg/util/native/qos_resources_test.go index b1c01b005..8f905c378 100644 --- a/pkg/util/native/qos_resources_test.go +++ b/pkg/util/native/qos_resources_test.go @@ -120,7 +120,9 @@ func Test_CalculateQoSResource(t *testing.T) { non0Mem: 1*1024*0124*1024 + DefaultReclaimedMemoryRequest*2, }, } { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() t.Logf("case: %v", tc.name) res, non0CPU, non0Mem := CalculateQoSResource(tc.pod) assert.Equal(t, tc.res, res) diff --git a/pkg/util/native/resources_test.go b/pkg/util/native/resources_test.go index 8635e2010..afac0a9da 100644 --- a/pkg/util/native/resources_test.go +++ b/pkg/util/native/resources_test.go @@ -134,7 +134,9 @@ func TestNeedUpdateResources(t *testing.T) { want: false, }, } { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() assert.Equal(t, tc.want, PodResourceDiff(tc.pod, tc.containerResourcesToUpdate)) }) } @@ -193,7 +195,10 @@ func TestMultiplyResourceQuantity(t *testing.T) { }, } for _, c := range cases { + c := c t.Run(c.name, func(t *testing.T) { + t.Parallel() + quant := MultiplyResourceQuantity(c.resourceName, c.quant, c.factor) assert.Equal(t, c.want, quant.Equal(c.res)) }) @@ -201,6 +206,8 @@ func TestMultiplyResourceQuantity(t *testing.T) { } func TestAggregateAvgQuantities(t *testing.T) { + t.Parallel() + type args struct { quantities []resource.Quantity } @@ -228,7 +235,10 @@ func TestAggregateAvgQuantities(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + assert.Equalf(t, tt.want, AggregateAvgQuantities(tt.args.quantities), "AggregateAvgQuantities(%v)", tt.args.quantities) }) } diff --git a/pkg/util/qos/net_enhancement_test.go b/pkg/util/qos/net_enhancement_test.go index 94b2487a8..941e12410 100644 --- a/pkg/util/qos/net_enhancement_test.go +++ b/pkg/util/qos/net_enhancement_test.go @@ -59,7 +59,10 @@ func TestGetPodNetClassID(t *testing.T) { expectClassID: 0, }, } { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() + t.Logf("case: %v", tc.name) gotExist, gotClassID, err := GetPodNetClassID(tc.pod.Annotations, consts.PodAnnotationNetClassKey) assert.NoError(t, err) diff --git a/pkg/util/qos/oom_priority_test.go b/pkg/util/qos/oom_priority_test.go index 11cc79b3a..70c04718b 100644 --- a/pkg/util/qos/oom_priority_test.go +++ b/pkg/util/qos/oom_priority_test.go @@ -210,7 +210,9 @@ func TestAlignOOMPriority(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() if got := AlignOOMPriority(tt.fields.qosLevel, tt.fields.userSpecifiedScore); got != tt.want { t.Errorf("AlignOOMPriority() = %v, want %v", got, tt.want) } diff --git a/pkg/util/service-discovery/service_single_port_sd_test.go b/pkg/util/service-discovery/service_single_port_sd_test.go index 7255e38df..9a17fedd6 100644 --- a/pkg/util/service-discovery/service_single_port_sd_test.go +++ b/pkg/util/service-discovery/service_single_port_sd_test.go @@ -35,6 +35,8 @@ import ( ) func TestServiceSinglePortSDManage(t *testing.T) { + t.Parallel() + server1 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) server2 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) defer func() { diff --git a/pkg/util/spd_baseline_test.go b/pkg/util/spd_baseline_test.go index f2a7cfd0b..b97833eb2 100644 --- a/pkg/util/spd_baseline_test.go +++ b/pkg/util/spd_baseline_test.go @@ -71,7 +71,9 @@ func TestBaselineCoefficient_Cmp(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() if got := tt.c.Cmp(tt.args.c1); got != tt.want { t.Errorf("Cmp() = %v, want %v", got, tt.want) } @@ -94,7 +96,9 @@ func TestBaselineCoefficient_String(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() if got := tt.c.String(); got != tt.want { t.Errorf("String() = %v, want %v", got, tt.want) } @@ -103,6 +107,8 @@ func TestBaselineCoefficient_String(t *testing.T) { } func TestGetPodBaselineCoefficient(t *testing.T) { + t.Parallel() + type args struct { pod *v1.Pod } @@ -129,7 +135,9 @@ func TestGetPodBaselineCoefficient(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() assert.Equal(t, tt.want, GetSPDBaselinePodMeta(tt.args.pod.ObjectMeta)) }) } @@ -166,7 +174,9 @@ func TestGetSPDBaselinePercentile(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() got, err := GetSPDBaselineSentinel(tt.args.spd) if (err != nil) != tt.wantErr { t.Errorf("GetSPDBaselineSentinel() error = %v, wantErr %v", err, tt.wantErr) @@ -270,7 +280,10 @@ func TestIsBaselinePod(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got, err := IsBaselinePod(tt.args.pod.ObjectMeta, tt.args.baselinePercent, tt.args.baselineSentinel) if (err != nil) != tt.wantErr { t.Errorf("IsBaselinePod() error = %v, wantErr %v", err, tt.wantErr) @@ -339,7 +352,10 @@ func TestSetSPDBaselinePercentile(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() + SetSPDBaselineSentinel(tt.args.spd, tt.args.c) assert.Equal(t, tt.args.spd, tt.wantSPD) }) diff --git a/pkg/util/spd_test.go b/pkg/util/spd_test.go index f8466a774..fc2c8a73f 100644 --- a/pkg/util/spd_test.go +++ b/pkg/util/spd_test.go @@ -175,6 +175,8 @@ func TestGetSPDForPod(t *testing.T) { } func TestGetExtendedIndicatorSpec(t *testing.T) { + t.Parallel() + type args struct { baselinePercent *int32 indicators interface{} @@ -224,7 +226,9 @@ func TestGetExtendedIndicatorSpec(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() got, err := GetExtendedIndicatorSpec(tt.args.baselinePercent, tt.args.indicators) if !tt.wantErr(t, err, fmt.Sprintf("GetExtendedIndicatorSpec(%v, %v)", tt.args.baselinePercent, tt.args.indicators)) { return @@ -235,6 +239,8 @@ func TestGetExtendedIndicatorSpec(t *testing.T) { } func TestCalculateSPDHash(t *testing.T) { + t.Parallel() + type args struct { spd *apiworkload.ServiceProfileDescriptor } @@ -310,7 +316,9 @@ func TestCalculateSPDHash(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() got, err := CalculateSPDHash(tt.args.spd) if !tt.wantErr(t, err, fmt.Sprintf("CalculateSPDHash(%v)", tt.args.spd)) { return diff --git a/pkg/util/vpa_test.go b/pkg/util/vpa_test.go index 23ab5bcef..cfd8f7fbc 100644 --- a/pkg/util/vpa_test.go +++ b/pkg/util/vpa_test.go @@ -150,7 +150,10 @@ func TestFindSpdByVpa(t *testing.T) { }, }, } { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() + spds := make([]runtime.Object, 0, len(tc.spd)) for _, spd := range tc.spd { spds = append(spds, spd) @@ -345,7 +348,10 @@ func TestGetWorkloadByVPA(t *testing.T) { gvk: rsGVK, }, } { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() + fakeDynamicClient := dynamicfake.NewSimpleDynamicClient(runtime.NewScheme()) dynamicFactory := dynamicinformer.NewDynamicSharedInformerFactory(fakeDynamicClient, 0) deployInformer := dynamicFactory.ForResource(deployGVR) @@ -420,7 +426,9 @@ func TestCheckVPARecommendationMatchVPA(t *testing.T) { want: false, }, } { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() match := CheckVPARecommendationMatchVPA(tc.vparec, tc.vpa) assert.Equal(t, tc.want, match) }) @@ -711,7 +719,9 @@ func TestIsVPAStatusLegal(t *testing.T) { msg: "resource cpu request greater than limit", }, } { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() isLegal, msg, err := CheckVPAStatusLegal(tc.vpa, tc.pods) assert.Equal(t, tc.legal, isLegal) assert.NoError(t, err) diff --git a/pkg/webhook/mutating/node/node_test.go b/pkg/webhook/mutating/node/node_test.go index 7ccf8717c..055804cd9 100644 --- a/pkg/webhook/mutating/node/node_test.go +++ b/pkg/webhook/mutating/node/node_test.go @@ -300,7 +300,10 @@ func TestMutateNode(t *testing.T) { } for _, c := range cases { + c := c t.Run(c.name, func(t *testing.T) { + t.Parallel() + controlCtx, err := katalystbase.GenerateFakeGenericContext() assert.NoError(t, err) diff --git a/pkg/webhook/mutating/pod/pod_test.go b/pkg/webhook/mutating/pod/pod_test.go index 645e42a62..f81f2c442 100644 --- a/pkg/webhook/mutating/pod/pod_test.go +++ b/pkg/webhook/mutating/pod/pod_test.go @@ -242,7 +242,10 @@ func TestMutatePod(t *testing.T) { }, }, } { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() + genericConf := &generic.GenericConfiguration{} webhookGenericConf := webhookconfig.NewGenericWebhookConfiguration() webhookGenericConf.DynamicGVResources = []string{