Skip to content

Commit

Permalink
test: Fix ConsolidationState() test failure in state testing (#1957) (
Browse files Browse the repository at this point in the history
#2040)

Co-authored-by: Jonathan Innis <[email protected]>
  • Loading branch information
rschalo and jonathan-innis authored Mar 4, 2025
1 parent f23919e commit 51c35cc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/actions/install-deps/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ runs:
# Root path permission workaround for caching https://github.com/actions/cache/issues/845#issuecomment-1252594999
- run: sudo chown "$USER" /usr/local
shell: bash
- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
- uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
id: cache-toolchain
with:
path: |
Expand Down
1 change: 1 addition & 0 deletions pkg/controllers/state/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ func (c *Cluster) ConsolidationState() time.Time {
func (c *Cluster) Reset() {
c.mu.Lock()
defer c.mu.Unlock()
c.clusterState = time.Time{}
c.nodes = map[string]*StateNode{}
c.nodeNameToProviderID = map[string]string{}
c.nodeClaimNameToProviderID = map[string]string{}
Expand Down
11 changes: 10 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 @@ -1443,7 +1444,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 @@ -1468,12 +1469,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 All @@ -1493,12 +1498,16 @@ var _ = Describe("Data Races", func() {
})
It("should ensure that calling Synced() is valid while making updates to NodeClaims", 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 51c35cc

Please sign in to comment.