Skip to content

Commit

Permalink
koordlet: fix flaky tests
Browse files Browse the repository at this point in the history
Signed-off-by: saintube <saintube@foxmail.com>
  • Loading branch information
saintube committed Jul 27, 2023
1 parent 9232daf commit 6142886
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
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

0 comments on commit 6142886

Please sign in to comment.