Skip to content

Commit

Permalink
run ut parallelly to make it fast
Browse files Browse the repository at this point in the history
  • Loading branch information
waynepeking348 committed Jul 14, 2023
1 parent 7f8ca3b commit 032025c
Show file tree
Hide file tree
Showing 116 changed files with 679 additions and 78 deletions.
6 changes: 3 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# options for analysis running
run:
# default concurrency is a available CPU number
concurrency: 4
# default concurrency is the available CPU number
concurrency: 16

# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 10m
timeout: 5m

# exit code when at least one issue was found, default is 1
issues-exit-code: 1
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ vet: ## Run go vet against code.

.PHONY: test
test: ## Run go test against code.
go test -v -coverprofile=coverage.txt -covermode=atomic -race -coverpkg=./... ./...
go test -v -coverprofile=coverage.txt -parallel=16 -p=16 -covermode=atomic -race -coverpkg=./... ./...

.PHONY: license
license:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
)

func TestMemoryPressureEvictionPluginOptions_ApplyTo(t *testing.T) {
t.Parallel()

options := NewMemoryPressureEvictionOptions()
configuration := eviction.NewMemoryPressureEvictionPluginConfiguration()

Expand Down
2 changes: 2 additions & 0 deletions pkg/agent/evictionmanager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ func makeEvictionManager() *EvictionManger {
}

func TestEvictionManger_collectEvictionResult(t *testing.T) {
t.Parallel()

mgr := makeEvictionManager()
tests := []struct {
name string
Expand Down
2 changes: 2 additions & 0 deletions pkg/agent/evictionmanager/plugin/memory/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func makeHelper() (*EvictionHelper, error) {
}

func TestEvictionHelper_getEvictionCmpFuncs(t *testing.T) {
t.Parallel()

helper, err := makeHelper()
assert.NoError(t, err)
assert.NotNil(t, helper)
Expand Down
6 changes: 6 additions & 0 deletions pkg/agent/evictionmanager/plugin/memory/numa_pressure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ func makeNumaPressureEvictionPlugin(conf *config.Configuration) (*NumaMemoryPres
}

func TestNewNumaPressureEvictionPlugin(t *testing.T) {
t.Parallel()

plugin, err := makeNumaPressureEvictionPlugin(makeConf())
assert.NoError(t, err)
assert.NotNil(t, plugin)
Expand All @@ -74,6 +76,8 @@ func TestNewNumaPressureEvictionPlugin(t *testing.T) {
}

func TestNumaMemoryPressurePlugin_ThresholdMet(t *testing.T) {
t.Parallel()

plugin, err := makeNumaPressureEvictionPlugin(makeConf())
assert.NoError(t, err)
assert.NotNil(t, plugin)
Expand Down Expand Up @@ -213,6 +217,8 @@ func TestNumaMemoryPressurePlugin_ThresholdMet(t *testing.T) {
}

func TestNumaMemoryPressurePlugin_GetTopEvictionPods(t *testing.T) {
t.Parallel()

plugin, err := makeNumaPressureEvictionPlugin(makeConf())
assert.NoError(t, err)
assert.NotNil(t, plugin)
Expand Down
2 changes: 2 additions & 0 deletions pkg/agent/evictionmanager/plugin/memory/rss_overuse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ func makeRssOverusePlugin(conf *config.Configuration) (*RssOveruseEvictionPlugin
}

func TestRssOveruseEvictionPlugin_GetEvictPods(t *testing.T) {
t.Parallel()

plugin, err := makeRssOverusePlugin(makeConf())
assert.NoError(t, err)
assert.NotNil(t, plugin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ func makeSystemPressureEvictionPlugin(conf *config.Configuration) (*SystemPressu
}

func TestNewSystemPressureEvictionPlugin(t *testing.T) {
t.Parallel()

plugin, err := makeSystemPressureEvictionPlugin(makeConf())
assert.NoError(t, err)
assert.NotNil(t, plugin)
Expand All @@ -111,6 +113,8 @@ func TestNewSystemPressureEvictionPlugin(t *testing.T) {
}

func TestSystemPressureEvictionPlugin_ThresholdMet(t *testing.T) {
t.Parallel()

plugin, err := makeSystemPressureEvictionPlugin(makeConf())
assert.NoError(t, err)
assert.NotNil(t, plugin)
Expand Down Expand Up @@ -290,6 +294,8 @@ func TestSystemPressureEvictionPlugin_ThresholdMet(t *testing.T) {
}

func TestSystemPressureEvictionPlugin_GetTopEvictionPods(t *testing.T) {
t.Parallel()

plugin, err := makeSystemPressureEvictionPlugin(makeConf())
assert.NoError(t, err)
assert.NotNil(t, plugin)
Expand Down
2 changes: 2 additions & 0 deletions pkg/agent/evictionmanager/plugin/reclaimed_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ func generateTestMetaServer(clientSet *client.GenericClientSet, conf *config.Con
}

func TestNewReclaimedResourcesEvictionPlugin(t *testing.T) {
t.Parallel()

testNodeName := "test-node"
testConf := generateTestConfiguration(t, testNodeName)
pods := []*corev1.Pod{
Expand Down
2 changes: 2 additions & 0 deletions pkg/agent/evictionmanager/podkiller/killer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (
)

func TestEvictionQueue(t *testing.T) {
t.Parallel()

pods := []*v1.Pod{
{
ObjectMeta: metav1.ObjectMeta{Name: "pod-1"},
Expand Down
2 changes: 2 additions & 0 deletions pkg/agent/evictionmanager/rule/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func makeRuledEvictPod(name, scope string) *RuledEvictPod {
}

func TestEvictionQueue(t *testing.T) {
t.Parallel()

for _, tc := range []struct {
comment string
q EvictionQueue
Expand Down
2 changes: 2 additions & 0 deletions pkg/agent/evictionmanager/rule/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func makeRuledEvictPodForSort(name, scope string, annotations map[string]string,
}

func TestEvictionStrategyImp(t *testing.T) {
t.Parallel()

testConf, _ := options.NewOptions().Config()
s := NewEvictionStrategyImpl(testConf)

Expand Down
14 changes: 14 additions & 0 deletions pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor/cpu.pb_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,22 @@ import (
)

func TestClientAddContainer(t *testing.T) {
t.Parallel()

client := NewCPUAdvisorClientStub()
_, _ = client.AddContainer(context.Background(), &advisorsvc.AddContainerRequest{})
}

func TestClientRemovePod(t *testing.T) {
t.Parallel()

client := NewCPUAdvisorClientStub()
_, _ = client.RemovePod(context.Background(), &advisorsvc.RemovePodRequest{})
}

func TestClientListAndWatch(t *testing.T) {
t.Parallel()

client := NewCPUAdvisorClientStub()
_, _ = client.ListAndWatch(context.Background(), &advisorsvc.Empty{})
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@ func makeConf(metricRingSize int, gracePeriod int64, loadUpperBoundRatio,
}

func makeState(topo *machine.CPUTopology) (qrmstate.State, error) {
tmpDir, err := os.MkdirTemp("", "checkpoint")
tmpDir, err := os.MkdirTemp("", "checkpoint-makeState")
if err != nil {
return nil, fmt.Errorf("make tmp dir for checkpoint failed with error: %v", err)
}
return qrmstate.NewCheckpointState(tmpDir, "test", "test", topo, false)
}

func TestNewCPUPressureLoadEviction(t *testing.T) {
t.Parallel()

as := require.New(t)

cpuTopology, err := machine.GenerateDummyCPUTopology(16, 2, 4)
Expand All @@ -102,6 +104,8 @@ func TestNewCPUPressureLoadEviction(t *testing.T) {
}

func TestThresholdMet(t *testing.T) {
t.Parallel()

as := require.New(t)

cpuTopology, err := machine.GenerateDummyCPUTopology(16, 2, 4)
Expand Down Expand Up @@ -385,6 +389,8 @@ func TestThresholdMet(t *testing.T) {
}

func TestGetTopEvictionPods(t *testing.T) {
t.Parallel()

as := require.New(t)

cpuTopology, err := machine.GenerateDummyCPUTopology(16, 2, 4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func makeSuppressionEvictionConf(cpuMaxSuppressionToleranceRate float64,
}

func TestNewCPUPressureSuppressionEviction(t *testing.T) {
t.Parallel()

as := require.New(t)

cpuTopology, err := machine.GenerateDummyCPUTopology(16, 2, 4)
Expand All @@ -71,6 +73,8 @@ func TestNewCPUPressureSuppressionEviction(t *testing.T) {
}

func TestCPUPressureSuppression_GetEvictPods(t *testing.T) {
t.Parallel()

as := require.New(t)

cpuTopology, err := machine.GenerateDummyCPUTopology(16, 2, 4)
Expand Down
10 changes: 4 additions & 6 deletions pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ const (
syncCPUIdlePeriod = 30 * time.Second
)

var (
transitionPeriod = 30 * time.Second
)

var (
readonlyStateLock sync.RWMutex
readonlyState state.ReadonlyState
Expand Down Expand Up @@ -125,6 +121,7 @@ type DynamicPolicy struct {
qosConfig *generic.QoSConfiguration
dynamicConfig *dynamicconfig.DynamicAgentConfiguration
podDebugAnnoKeys []string
transitionPeriod time.Duration
}

func NewDynamicPolicy(agentCtx *agent.GenericContext, conf *config.Configuration,
Expand Down Expand Up @@ -196,6 +193,7 @@ func NewDynamicPolicy(agentCtx *agent.GenericContext, conf *config.Configuration
enableCPUIdle: conf.CPUQRMPluginConfig.EnableCPUIdle,
reclaimRelativeRootCgroupPath: conf.ReclaimRelativeRootCgroupPath,
podDebugAnnoKeys: conf.PodDebugAnnoKeys,
transitionPeriod: time.Second,
}

// register allocation behaviors for pods with different QoS level
Expand All @@ -212,7 +210,7 @@ func NewDynamicPolicy(agentCtx *agent.GenericContext, conf *config.Configuration
consts.PodAnnotationQoSLevelReclaimedCores: policyImplement.reclaimedCoresHintHandler,
}

state.GetContainerRequestedCores = policyImplement.getContainerRequestedCores
state.SetContainerRequestedCores(policyImplement.getContainerRequestedCores)

if err := policyImplement.cleanPools(); err != nil {
return false, agent.ComponentStub{}, fmt.Errorf("cleanPools failed with error: %v", err)
Expand Down Expand Up @@ -420,7 +418,7 @@ func (p *DynamicPolicy) GetResourcesAllocation(_ context.Context,

allocationInfo.InitTimestamp = time.Now().Format(util.QRMTimeFormat)
p.state.SetAllocationInfo(podUID, containerName, allocationInfo)
} else if allocationInfo.RampUp && time.Now().After(initTs.Add(transitionPeriod)) {
} else if allocationInfo.RampUp && time.Now().After(initTs.Add(p.transitionPeriod)) {
general.Infof("pod: %s/%s, container: %s ramp up finished", allocationInfo.PodNamespace, allocationInfo.PodName, allocationInfo.ContainerName)
allocationInfo.RampUp = false
p.state.SetAllocationInfo(podUID, containerName, allocationInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ func (p *DynamicPolicy) applyBlocks(blockCPUSet advisorapi.BlockCPUSet, resp *ad

// adapt to old checkpoint without RequestQuantity property
if newEntries[podUID][containerName] != nil {
newEntries[podUID][containerName].RequestQuantity = state.GetContainerRequestedCores(allocationInfo)
newEntries[podUID][containerName].RequestQuantity = state.GetContainerRequestedCores()(allocationInfo)
continue
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ func (p *DynamicPolicy) putAllocationsAndAdjustAllocationEntries(allocationInfos
return fmt.Errorf("allocationInfo points to empty poolName")
}

reqInt := state.GetContainerRequestedCores(allocationInfo)
reqInt := state.GetContainerRequestedCores()(allocationInfo)
poolsQuantityMap[poolName] += reqInt
}

Expand Down Expand Up @@ -723,7 +723,7 @@ func (p *DynamicPolicy) applyPoolsAndIsolatedInfo(poolsCPUSet map[string]machine
continue
}

reqInt := state.GetContainerRequestedCores(allocationInfo)
reqInt := state.GetContainerRequestedCores()(allocationInfo)
if newPodEntries[podUID][containerName] != nil {
// adapt to old checkpoint without RequestQuantity property
newPodEntries[podUID][containerName].RequestQuantity = reqInt
Expand Down
Loading

0 comments on commit 032025c

Please sign in to comment.