From 3c345abafd024853d8ff0fb332db6076cfc610c5 Mon Sep 17 00:00:00 2001 From: saadali Date: Fri, 27 May 2016 01:19:25 -0700 Subject: [PATCH] Fix DATA RACE in unit tests: reconciler_test.go --- pkg/controller/volume/reconciler/reconciler_test.go | 8 ++++---- pkg/volume/testing/testing.go | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pkg/controller/volume/reconciler/reconciler_test.go b/pkg/controller/volume/reconciler/reconciler_test.go index c6109632cd8..c0c513681c2 100644 --- a/pkg/controller/volume/reconciler/reconciler_test.go +++ b/pkg/controller/volume/reconciler/reconciler_test.go @@ -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 @@ -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 diff --git a/pkg/volume/testing/testing.go b/pkg/volume/testing/testing.go index a58a063a51c..b5f81926d22 100644 --- a/pkg/volume/testing/testing.go +++ b/pkg/volume/testing/testing.go @@ -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() @@ -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()