Skip to content

Commit

Permalink
Fix ConsolidationState() test failure in state testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis committed Feb 3, 2025
1 parent 6431d04 commit 27901aa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pkg/controllers/state/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,17 @@ func (c *Cluster) ConsolidationState() time.Time {
func (c *Cluster) Reset() {
c.mu.Lock()
defer c.mu.Unlock()
c.clusterState = time.Time{}
c.unsyncedStartTime = time.Time{}
c.nodes = map[string]*StateNode{}
c.nodeNameToProviderID = map[string]string{}
c.nodeClaimNameToProviderID = map[string]string{}
c.bindings = map[types.NamespacedName]string{}
c.antiAffinityPods = sync.Map{}
c.daemonSetPods = sync.Map{}
c.podAcks = sync.Map{}
c.podsSchedulingAttempted = sync.Map{}
c.podsSchedulableTimes = sync.Map{}
}

func (c *Cluster) GetDaemonSetPod(daemonset *appsv1.DaemonSet) *corev1.Pod {
Expand Down
7 changes: 6 additions & 1 deletion pkg/controllers/state/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"math/rand"
"net"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -1474,7 +1475,7 @@ var _ = Describe("Consolidated State", func() {
cluster.MarkUnconsolidated()
Expect(cluster.ConsolidationState()).ToNot(Equal(state))
})
It("should update the consolidated value when consolidation timeout (5m) has passed and state hasn't changed", func() {
It("should update the consolidated value when state timeout (5m) has passed and state hasn't changed", func() {
state := cluster.ConsolidationState()

fakeClock.Step(time.Minute)
Expand All @@ -1499,12 +1500,16 @@ var _ = Describe("Consolidated State", func() {
var _ = Describe("Data Races", func() {
It("should ensure that calling Synced() is valid while making updates to Nodes", func() {
cancelCtx, cancel := context.WithCancel(ctx)
var wg sync.WaitGroup
DeferCleanup(func() {
cancel()
wg.Wait()
})

// Keep calling Synced for the entirety of this test
wg.Add(1)
go func() {
defer wg.Done()
for {
_ = cluster.Synced(ctx)
if cancelCtx.Err() != nil {
Expand Down

0 comments on commit 27901aa

Please sign in to comment.