Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

koordlet: fix flaky tests #1498

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions pkg/koordlet/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,23 @@ package config
import (
"flag"
"testing"

"github.com/stretchr/testify/assert"
)

func TestConfiguration_InitFlags(t *testing.T) {
cmdArgs := []string{
"",
"--collect-res-used-interval=2s",
"--reconcile-interval-seconds=5",
"--cgroup-root-dir=/host-cgroup/",
"--feature-gates=AllBeta=true,AllAlpha=false",
}
t.Run("ensure not panic", func(t *testing.T) {
fs := flag.NewFlagSet(cmdArgs[0], flag.ExitOnError)
cfg := NewConfiguration()
cfg.InitFlags(flag.CommandLine)
flag.Parse()
cfg.InitFlags(fs)
err := fs.Parse(cmdArgs[1:])
assert.NoError(t, err)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ func Test_collectBECPUResourceMetric(t *testing.T) {
// BECPUUsage
currentBECPUMilliUsage, err := beCPUUsageAggregateResult.Value(metriccache.AggregationTypeLast)
assert.NoError(t, err)
assert.Equal(t, float64(4*1000), currentBECPUMilliUsage, "checkRequest")
// check roughly; tolerant 1 second error
assert.True(t, currentBECPUMilliUsage > float64(3*1000) && currentBECPUMilliUsage < float64(5*1000), "checkUsage")
// BECPURequest
currentBECPUMilliRequest, _ := beCPURequeestAggregateResult.Value(metriccache.AggregationTypeLast)
assert.NoError(t, err)
assert.Equal(t, float64(1500), currentBECPUMilliRequest, "checkUsage")
assert.Equal(t, float64(1500), currentBECPUMilliRequest, "checkRequest")
// BECPULimit
currentBECPUMilliRealLimit, _ := beCPURealLimitAggregateResult.Value(metriccache.AggregationTypeLast)
assert.NoError(t, err)
Expand Down
12 changes: 9 additions & 3 deletions pkg/koordlet/qosmanager/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ func Test_NewDefaultConfig(t *testing.T) {
}

func Test_InitFlags(t *testing.T) {
cfg := NewDefaultConfig()
cfg.InitFlags(flag.CommandLine)
flag.Parse()
cmdArgs := []string{
"",
"--qos-plugins=AllAlpha=false",
}
fs := flag.NewFlagSet(cmdArgs[0], flag.ExitOnError)
c := NewDefaultConfig()
c.InitFlags(fs)
err := fs.Parse(cmdArgs[1:])
assert.NoError(t, err)
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func newNodeResourceTopologyInformer(client topologyclientset.Interface, nodeNam
cache.Indexers{},
)
}

func (s *nodeTopoInformer) createNodeTopoIfNotExist() {
node := s.nodeInformer.GetNode()
topologyName := node.Name
Expand Down Expand Up @@ -607,7 +608,6 @@ func (s *nodeTopoInformer) calCPUSharePools(sharedPoolCPUs map[int32]*extension.
}

func (s *nodeTopoInformer) calCPUTopology() (*metriccache.NodeCPUInfo, *extension.CPUTopology, map[int32]*extension.CPUInfo, error) {

nodeCPUInfoRaw, exist := s.metricCache.Get(metriccache.NodeCPUInfoKey)
if !exist {
klog.Warning("failed to get node cpu info : not exist")
Expand Down