Commit 628959b3 authored by James Rasell's avatar James Rasell Committed by Tim Gross
Browse files

Merge pull request #10752 from hashicorp/b-fix-test-datarace-volumewatcher

volumewatcher: fix test data race.
parent 6efeeae6
Branches unavailable v1.0.18 v1.0.17
No related merge requests found
Showing with 14 additions and 2 deletions
+14 -2
......@@ -43,10 +43,12 @@ func TestVolumeWatch_EnableDisable(t *testing.T) {
err = srv.State().CSIVolumeClaim(index, vol.Namespace, vol.ID, claim)
require.NoError(err)
require.Eventually(func() bool {
watcher.wlock.RLock()
defer watcher.wlock.RUnlock()
return 1 == len(watcher.watchers)
}, time.Second, 10*time.Millisecond)
watcher.SetEnabled(false, srv.State())
watcher.SetEnabled(false, nil)
require.Equal(0, len(watcher.watchers))
}
......@@ -77,16 +79,20 @@ func TestVolumeWatch_Checkpoint(t *testing.T) {
// we should get or start up a watcher when we get an update for
// the volume from the state store
require.Eventually(func() bool {
watcher.wlock.RLock()
defer watcher.wlock.RUnlock()
return 1 == len(watcher.watchers)
}, time.Second, 10*time.Millisecond)
// step-down (this is sync, but step-up is async)
watcher.SetEnabled(false, srv.State())
watcher.SetEnabled(false, nil)
require.Equal(0, len(watcher.watchers))
// step-up again
watcher.SetEnabled(true, srv.State())
require.Eventually(func() bool {
watcher.wlock.RLock()
defer watcher.wlock.RUnlock()
return 1 == len(watcher.watchers) &&
!watcher.watchers[vol.ID+vol.Namespace].isRunning()
}, time.Second, 10*time.Millisecond)
......@@ -128,6 +134,8 @@ func TestVolumeWatch_StartStop(t *testing.T) {
// assert we get a watcher; there are no claims so it should immediately stop
require.Eventually(func() bool {
watcher.wlock.RLock()
defer watcher.wlock.RUnlock()
return 1 == len(watcher.watchers) &&
!watcher.watchers[vol.ID+vol.Namespace].isRunning()
}, time.Second*2, 10*time.Millisecond)
......@@ -177,6 +185,8 @@ func TestVolumeWatch_StartStop(t *testing.T) {
}, time.Second*2, 10*time.Millisecond)
require.Eventually(func() bool {
watcher.wlock.RLock()
defer watcher.wlock.RUnlock()
return !watcher.watchers[vol.ID+vol.Namespace].isRunning()
}, time.Second*5, 10*time.Millisecond)
}
......@@ -209,6 +219,8 @@ func TestVolumeWatch_RegisterDeregister(t *testing.T) {
// watcher should be started but immediately stopped
require.Eventually(func() bool {
watcher.wlock.RLock()
defer watcher.wlock.RUnlock()
return 1 == len(watcher.watchers)
}, time.Second, 10*time.Millisecond)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment