@@ -43,6 +43,9 @@ import (
4343// Tests to ensure that if a certificate is immediately ready to be requested when NodePublishVolume
4444// is called, the call will be blocking until the volume is actually ready.
4545func Test_PublishCallBlocksIfReadyToRequestDespiteContinueOnNotReadyTrue (t * testing.T ) {
46+ ctx , cancel := context .WithTimeout (context .Background (), time .Second * 10 )
47+ defer cancel ()
48+
4649 store := storage .NewMemoryFS ()
4750 clock := fakeclock .NewFakeClock (time .Now ())
4851
@@ -75,17 +78,13 @@ func Test_PublishCallBlocksIfReadyToRequestDespiteContinueOnNotReadyTrue(t *test
7578 defer stop ()
7679
7780 // Setup a routine to issue/sign the request IF it is created
78- stopCh := make (chan struct {})
79- go testutil .IssueAllRequests (t , opts .Client , "certificaterequest-namespace" , stopCh , selfSignedExampleCertificate , []byte ("ca bytes" ))
80- defer close (stopCh )
81+ go testutil .IssueAllRequests (ctx , t , opts .Client , "certificaterequest-namespace" , selfSignedExampleCertificate , []byte ("ca bytes" ))
8182
8283 tmpDir , err := os .MkdirTemp ("" , "*" )
8384 if err != nil {
8485 t .Fatal (err )
8586 }
8687 defer os .RemoveAll (tmpDir )
87- ctx , cancel := context .WithTimeout (context .Background (), time .Second * 10 )
88- defer cancel ()
8988 // This call will block until an issuance is successfully completed.
9089 _ , err = cl .NodePublishVolume (ctx , & csi.NodePublishVolumeRequest {
9190 VolumeId : "test-vol" ,
@@ -116,6 +115,9 @@ func Test_PublishCallBlocksIfReadyToRequestDespiteContinueOnNotReadyTrue(t *test
116115}
117116
118117func Test_CompletesIfNotReadyToRequest_ContinueOnNotReadyEnabled (t * testing.T ) {
118+ ctx , cancel := context .WithTimeout (context .Background (), time .Second * 10 )
119+ defer cancel ()
120+
119121 store := storage .NewMemoryFS ()
120122 clock := fakeclock .NewFakeClock (time .Now ())
121123
@@ -156,17 +158,13 @@ func Test_CompletesIfNotReadyToRequest_ContinueOnNotReadyEnabled(t *testing.T) {
156158 defer stop ()
157159
158160 // Setup a routine to issue/sign the request IF it is created
159- stopCh := make (chan struct {})
160- go testutil .IssueAllRequests (t , opts .Client , "certificaterequest-namespace" , stopCh , selfSignedExampleCertificate , []byte ("ca bytes" ))
161- defer close (stopCh )
161+ go testutil .IssueAllRequests (ctx , t , opts .Client , "certificaterequest-namespace" , selfSignedExampleCertificate , []byte ("ca bytes" ))
162162
163163 tmpDir , err := os .MkdirTemp ("" , "*" )
164164 if err != nil {
165165 t .Fatal (err )
166166 }
167167 defer os .RemoveAll (tmpDir )
168- ctx , cancel := context .WithTimeout (context .Background (), time .Second * 10 )
169- defer cancel ()
170168 _ , err = cl .NodePublishVolume (ctx , & csi.NodePublishVolumeRequest {
171169 VolumeId : "test-vol" ,
172170 VolumeContext : map [string ]string {
@@ -181,7 +179,7 @@ func Test_CompletesIfNotReadyToRequest_ContinueOnNotReadyEnabled(t *testing.T) {
181179 t .Fatal (err )
182180 }
183181
184- if err := wait .PollUntil ( time .Second , func () (done bool , err error ) {
182+ if err := wait .PollUntilContextCancel ( ctx , time .Second , true , func (ctx context. Context ) (done bool , err error ) {
185183 files , err := store .ReadFiles ("test-vol" )
186184 if errors .Is (err , storage .ErrNotFound ) || len (files ) <= 1 {
187185 return false , nil
@@ -196,12 +194,15 @@ func Test_CompletesIfNotReadyToRequest_ContinueOnNotReadyEnabled(t *testing.T) {
196194 return false , fmt .Errorf ("unexpected certificate data: %v" , files ["cert" ])
197195 }
198196 return true , nil
199- }, ctx . Done () ); err != nil {
197+ }); err != nil {
200198 t .Error (err )
201199 }
202200}
203201
204202func TestFailsIfNotReadyToRequest_ContinueOnNotReadyDisabled (t * testing.T ) {
203+ ctx , cancel := context .WithTimeout (context .Background (), time .Second )
204+ defer cancel ()
205+
205206 store := storage .NewMemoryFS ()
206207 clock := fakeclock .NewFakeClock (time .Now ())
207208
@@ -236,16 +237,12 @@ func TestFailsIfNotReadyToRequest_ContinueOnNotReadyDisabled(t *testing.T) {
236237 defer stop ()
237238
238239 // Setup a routine to issue/sign the request IF it is created
239- stopCh := make (chan struct {})
240- go testutil .IssueAllRequests (t , opts .Client , "certificaterequest-namespace" , stopCh , selfSignedExampleCertificate , []byte ("ca bytes" ))
241- defer close (stopCh )
240+ go testutil .IssueAllRequests (ctx , t , opts .Client , "certificaterequest-namespace" , selfSignedExampleCertificate , []byte ("ca bytes" ))
242241 tmpDir , err := os .MkdirTemp ("" , "*" )
243242 if err != nil {
244243 t .Fatal (err )
245244 }
246245 defer os .RemoveAll (tmpDir )
247- ctx , cancel := context .WithTimeout (context .Background (), time .Second )
248- defer cancel ()
249246 _ , err = cl .NodePublishVolume (ctx , & csi.NodePublishVolumeRequest {
250247 VolumeId : "test-vol" ,
251248 VolumeContext : map [string ]string {
@@ -265,13 +262,13 @@ func TestFailsIfNotReadyToRequest_ContinueOnNotReadyDisabled(t *testing.T) {
265262 // being cleaned up of the persisted metadata file.
266263 ctx , cancel2 := context .WithTimeout (context .Background (), time .Second )
267264 defer cancel2 ()
268- if err := wait .PollUntil ( time .Millisecond * 100 , func () (bool , error ) {
265+ if err := wait .PollUntilContextCancel ( ctx , time .Millisecond * 100 , true , func (ctx context. Context ) (bool , error ) {
269266 _ , err := store .ReadFiles ("test-vol" )
270267 if err != storage .ErrNotFound {
271268 return false , nil
272269 }
273270 return true , nil
274- }, ctx . Done () ); err != nil {
271+ }); err != nil {
275272 t .Errorf ("failed to wait for storage backend to return NotFound: %v" , err )
276273 }
277274}
0 commit comments