Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <admin@liudos.us>
  • Loading branch information
lhy1024 committed Sep 21, 2023
1 parent e3e346a commit c49c9f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 8 additions & 0 deletions pkg/utils/syncutil/flexible_wait_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,11 @@ func (fwg *FlexibleWaitGroup) Wait() {
}
fwg.Unlock()
}

// getCount returns the current count of the FlexibleWaitGroup.
// It is only used for testing.
func (fwg *FlexibleWaitGroup) getCount() int{
fwg.Lock()
defer fwg.Unlock()
return fwg.count
}
8 changes: 4 additions & 4 deletions pkg/utils/syncutil/flexible_wait_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestNegativeDelta(t *testing.T) {
fwg.Done()
}()
fwg.Wait()
require.Equal(0, fwg.count)
require.Equal(0, fwg.getCount())
}

// TestMultipleWait tests the case where Wait is called multiple times concurrently.
Expand All @@ -108,7 +108,7 @@ func TestMultipleWait(t *testing.T) {
}()
<-done
<-done
require.Equal(0, fwg.count)
require.Equal(0, fwg.getCount())
}

// TestAddAfterWaitFinished tests the case where Add is called after Wait has finished.
Expand All @@ -126,7 +126,7 @@ func TestAddAfterWaitFinished(t *testing.T) {
}()
<-done
fwg.Add(1)
require.Equal(1, fwg.count)
require.Equal(1, fwg.getCount())
fwg.Done()
require.Equal(0, fwg.count)
require.Equal(0, fwg.getCount())
}

0 comments on commit c49c9f6

Please sign in to comment.