Skip to content

Commit b713645

Browse files
test: Fix ConsolidationState() test failure in state testing (#1957) 1.1.x (#2039)
Co-authored-by: Jonathan Innis <[email protected]>
1 parent f7cf5bb commit b713645

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

.github/actions/install-deps/action.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ runs:
1616
# Root path permission workaround for caching https://github.com/actions/cache/issues/845#issuecomment-1252594999
1717
- run: sudo chown "$USER" /usr/local
1818
shell: bash
19-
- uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
19+
- uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
2020
id: cache-toolchain
2121
with:
2222
path: |

pkg/controllers/state/cluster.go

+5
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,17 @@ func (c *Cluster) ConsolidationState() time.Time {
426426
func (c *Cluster) Reset() {
427427
c.mu.Lock()
428428
defer c.mu.Unlock()
429+
c.clusterState = time.Time{}
430+
c.unsyncedStartTime = time.Time{}
429431
c.nodes = map[string]*StateNode{}
430432
c.nodeNameToProviderID = map[string]string{}
431433
c.nodeClaimNameToProviderID = map[string]string{}
432434
c.bindings = map[types.NamespacedName]string{}
433435
c.antiAffinityPods = sync.Map{}
434436
c.daemonSetPods = sync.Map{}
437+
c.podAcks = sync.Map{}
438+
c.podsSchedulingAttempted = sync.Map{}
439+
c.podsSchedulableTimes = sync.Map{}
435440
}
436441

437442
func (c *Cluster) GetDaemonSetPod(daemonset *appsv1.DaemonSet) *corev1.Pod {

pkg/controllers/state/suite_test.go

+16-11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"math/rand"
2323
"net"
24+
"sync"
2425
"testing"
2526
"time"
2627

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

14801481
fakeClock.Step(time.Minute)
@@ -1497,14 +1498,21 @@ var _ = Describe("Consolidated State", func() {
14971498
})
14981499

14991500
var _ = Describe("Data Races", func() {
1501+
var wg sync.WaitGroup
1502+
var cancelCtx context.Context
1503+
var cancel context.CancelFunc
1504+
BeforeEach(func() {
1505+
cancelCtx, cancel = context.WithCancel(ctx)
1506+
})
1507+
AfterEach(func() {
1508+
cancel()
1509+
wg.Wait()
1510+
})
15001511
It("should ensure that calling Synced() is valid while making updates to Nodes", func() {
1501-
cancelCtx, cancel := context.WithCancel(ctx)
1502-
DeferCleanup(func() {
1503-
cancel()
1504-
})
1505-
15061512
// Keep calling Synced for the entirety of this test
1513+
wg.Add(1)
15071514
go func() {
1515+
defer wg.Done()
15081516
for {
15091517
_ = cluster.Synced(ctx)
15101518
if cancelCtx.Err() != nil {
@@ -1523,13 +1531,10 @@ var _ = Describe("Data Races", func() {
15231531
}
15241532
})
15251533
It("should ensure that calling Synced() is valid while making updates to NodeClaims", func() {
1526-
cancelCtx, cancel := context.WithCancel(ctx)
1527-
DeferCleanup(func() {
1528-
cancel()
1529-
})
1530-
15311534
// Keep calling Synced for the entirety of this test
1535+
wg.Add(1)
15321536
go func() {
1537+
defer wg.Done()
15331538
for {
15341539
_ = cluster.Synced(ctx)
15351540
if cancelCtx.Err() != nil {

0 commit comments

Comments
 (0)