Skip to content

Commit

Permalink
Merge pull request kubernetes#26407 from saad-ali/fixRaceReconcilerTest
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue

Fix DATA RACE in unit tests: reconciler_test.go

Fixes kubernetes#26377
  • Loading branch information
k8s-merge-robot committed May 27, 2016
2 parents 1cb0888 + 3c345ab commit 071cfe6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/controller/volume/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,14 @@ func waitForAttachCallCount(
t *testing.T,
expectedAttachCallCount int,
fakePlugin *volumetesting.FakeVolumePlugin) {
if len(fakePlugin.Attachers) == 0 && expectedAttachCallCount == 0 {
if len(fakePlugin.GetAttachers()) == 0 && expectedAttachCallCount == 0 {
return
}

err := retryWithExponentialBackOff(
time.Duration(5*time.Millisecond),
func() (bool, error) {
for i, attacher := range fakePlugin.Attachers {
for i, attacher := range fakePlugin.GetAttachers() {
actualCallCount := attacher.GetAttachCallCount()
if actualCallCount == expectedAttachCallCount {
return true, nil
Expand Down Expand Up @@ -293,14 +293,14 @@ func waitForDetachCallCount(
t *testing.T,
expectedDetachCallCount int,
fakePlugin *volumetesting.FakeVolumePlugin) {
if len(fakePlugin.Detachers) == 0 && expectedDetachCallCount == 0 {
if len(fakePlugin.GetDetachers()) == 0 && expectedDetachCallCount == 0 {
return
}

err := retryWithExponentialBackOff(
time.Duration(5*time.Millisecond),
func() (bool, error) {
for i, detacher := range fakePlugin.Detachers {
for i, detacher := range fakePlugin.GetDetachers() {
actualCallCount := detacher.GetDetachCallCount()
if actualCallCount == expectedDetachCallCount {
return true, nil
Expand Down
12 changes: 12 additions & 0 deletions pkg/volume/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ func (plugin *FakeVolumePlugin) NewAttacher() (Attacher, error) {
return plugin.getFakeVolume(&plugin.Attachers), nil
}

func (plugin *FakeVolumePlugin) GetAttachers() (Attachers []*FakeVolume) {
plugin.RLock()
defer plugin.RUnlock()
return plugin.Attachers
}

func (plugin *FakeVolumePlugin) GetNewAttacherCallCount() int {
plugin.RLock()
defer plugin.RUnlock()
Expand All @@ -219,6 +225,12 @@ func (plugin *FakeVolumePlugin) NewDetacher() (Detacher, error) {
return plugin.getFakeVolume(&plugin.Detachers), nil
}

func (plugin *FakeVolumePlugin) GetDetachers() (Detachers []*FakeVolume) {
plugin.RLock()
defer plugin.RUnlock()
return plugin.Detachers
}

func (plugin *FakeVolumePlugin) GetNewDetacherCallCount() int {
plugin.RLock()
defer plugin.RUnlock()
Expand Down

0 comments on commit 071cfe6

Please sign in to comment.