Skip to content

Commit

Permalink
run ut parallelly to make it fast (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
waynepeking348 authored Jul 17, 2023
1 parent 3ecec50 commit 12aef70
Show file tree
Hide file tree
Showing 123 changed files with 839 additions and 193 deletions.
24 changes: 22 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
workflow_dispatch: {}

jobs:
lint:
name: Lint
fmt:
name: Format
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
Expand All @@ -24,10 +24,30 @@ jobs:
run: |
make fmt && git add pkg cmd &&
git diff --cached --exit-code || (echo 'Please run "make fmt" to verify gofmt' && exit 1);
vet:
name: Vet
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: go.mod
cache: false
- name: Verify govet
run: |
make vet && git add pkg cmd &&
git diff --cached --exit-code || (echo 'Please run "make vet" to verify govet' && exit 1);
lint:
name: Lint
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: go.mod
cache: false
- uses: golangci/golangci-lint-action@v3
with:
args: --verbose --out-${NO_FUTURE}format colored-line-number --config .golangci.yml
Expand Down
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 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
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=./... ./pkg/...

.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 @@ -43,7 +43,7 @@ import (

const (
defaultCPUMaxSuppressionToleranceRate = 5.0
defaultCPUMinSuppressionToleranceDuration = 1 * time.Second
defaultCPUMinSuppressionToleranceDuration = 10 * time.Millisecond
)

func makeSuppressionEvictionConf(cpuMaxSuppressionToleranceRate float64,
Expand All @@ -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 Expand Up @@ -304,7 +308,7 @@ func TestCPUPressureSuppression_GetEvictPods(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, resp)

time.Sleep(1 * time.Second)
time.Sleep(defaultCPUMinSuppressionToleranceDuration)

resp, err = plugin.GetEvictPods(context.TODO(), &evictionpluginapi.GetEvictPodsRequest{
ActivePods: pods,
Expand Down
12 changes: 5 additions & 7 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 @@ -324,7 +322,7 @@ func (p *DynamicPolicy) Start() (err error) {
general.Infof("sync existing containers to cpu advisor successfully")

// call lw of CPUAdvisorServer and do allocation
if err := p.lwCPUAdvisorServer(p.stopCh); err != nil {
if err = p.lwCPUAdvisorServer(p.stopCh); err != nil {
general.Errorf("lwCPUAdvisorServer failed with error: %v", err)
} else {
general.Infof("lwCPUAdvisorServer finished")
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
Loading

0 comments on commit 12aef70

Please sign in to comment.