@@ -39,21 +39,18 @@ func TestRealWaiterWaitMissingFile(t *testing.T) {
3939 }
4040 os .Remove (tmp .Name ())
4141 rw := realWaiter {}
42- doneCh := make (chan struct {} )
42+ errCh := make (chan error )
4343 go func () {
44- err := rw .setWaitPollingInterval (testWaitPollingInterval ).Wait (context .Background (), tmp .Name (), false , false )
45- if err != nil {
46- t .Errorf ("error waiting on tmp file %q" , tmp .Name ())
47- }
48- close (doneCh )
44+ err := rw .setWaitPollingInterval (testWaitPollingInterval ).Wait (t .Context (), tmp .Name (), false , false )
45+ errCh <- err
4946 }()
5047
5148 delay := time .NewTimer (2 * testWaitPollingInterval )
5249 select {
5350 case <- delay .C :
5451 // Success
55- case <- doneCh :
56- t .Errorf ("did not expect Wait() to have detected a file at path %q" , tmp .Name ())
52+ case err := <- errCh :
53+ t .Errorf ("did not expect Wait() to have detected a file at path %q, err: %v " , tmp .Name (), err )
5754 if ! delay .Stop () {
5855 <- delay .C
5956 }
@@ -69,7 +66,7 @@ func TestRealWaiterWaitWithFile(t *testing.T) {
6966 rw := realWaiter {}
7067 doneCh := make (chan struct {})
7168 go func () {
72- err := rw .setWaitPollingInterval (testWaitPollingInterval ).Wait (context . Background (), tmp .Name (), false , false )
69+ err := rw .setWaitPollingInterval (testWaitPollingInterval ).Wait (t . Context (), tmp .Name (), false , false )
7370 if err != nil {
7471 t .Errorf ("error waiting on tmp file %q" , tmp .Name ())
7572 }
@@ -91,20 +88,19 @@ func TestRealWaiterWaitMissingContent(t *testing.T) {
9188 }
9289 defer os .Remove (tmp .Name ())
9390 rw := realWaiter {}
94- doneCh := make (chan struct {} )
91+ errCh := make (chan error )
9592 go func () {
96- err := rw .setWaitPollingInterval (testWaitPollingInterval ).Wait (context .Background (), tmp .Name (), true , false )
97- if err != nil {
98- t .Errorf ("error waiting on tmp file %q" , tmp .Name ())
99- }
100- close (doneCh )
93+ err := rw .setWaitPollingInterval (testWaitPollingInterval ).Wait (t .Context (), tmp .Name (), true , false )
94+ errCh <- err
10195 }()
10296 delay := time .NewTimer (2 * testWaitPollingInterval )
10397 select {
10498 case <- delay .C :
10599 // Success
106- case <- doneCh :
107- t .Errorf ("no data was written to tmp file, did not expect Wait() to have detected a non-zero file size and returned" )
100+ case err := <- errCh :
101+ if err == nil {
102+ t .Errorf ("no data was written to tmp file, did not expect Wait() to have detected a non-zero file size and returned" )
103+ }
108104 if ! delay .Stop () {
109105 <- delay .C
110106 }
@@ -120,7 +116,7 @@ func TestRealWaiterWaitWithContent(t *testing.T) {
120116 rw := realWaiter {}
121117 doneCh := make (chan struct {})
122118 go func () {
123- err := rw .setWaitPollingInterval (testWaitPollingInterval ).Wait (context . Background (), tmp .Name (), true , false )
119+ err := rw .setWaitPollingInterval (testWaitPollingInterval ).Wait (t . Context (), tmp .Name (), true , false )
124120 if err != nil {
125121 t .Errorf ("error waiting on tmp file %q" , tmp .Name ())
126122 }
@@ -149,7 +145,7 @@ func TestRealWaiterWaitWithErrorWaitfile(t *testing.T) {
149145 doneCh := make (chan struct {})
150146 go func () {
151147 // error of type skipError is returned after encountering a error waitfile
152- err := rw .setWaitPollingInterval (testWaitPollingInterval ).Wait (context . Background (), tmpFileName , false , false )
148+ err := rw .setWaitPollingInterval (testWaitPollingInterval ).Wait (t . Context (), tmpFileName , false , false )
153149 if err == nil {
154150 t .Errorf ("expected skipError upon encounter error waitfile" )
155151 }
@@ -180,7 +176,7 @@ func TestRealWaiterWaitWithBreakpointOnFailure(t *testing.T) {
180176 doneCh := make (chan struct {})
181177 go func () {
182178 // When breakpoint on failure is enabled skipError shouldn't be returned for a error waitfile
183- err := rw .setWaitPollingInterval (testWaitPollingInterval ).Wait (context . Background (), tmpFileName , false , true )
179+ err := rw .setWaitPollingInterval (testWaitPollingInterval ).Wait (t . Context (), tmpFileName , false , true )
184180 if err != nil {
185181 t .Errorf ("error waiting on tmp file %q" , tmp .Name ())
186182 }
@@ -201,7 +197,7 @@ func TestRealWaiterWaitWithContextCanceled(t *testing.T) {
201197 t .Errorf ("error creating temp file: %v" , err )
202198 }
203199 defer os .Remove (tmp .Name ())
204- ctx , cancel := context .WithCancel (context . Background ())
200+ ctx , cancel := context .WithCancel (t . Context ())
205201 rw := realWaiter {}
206202 errCh := make (chan error )
207203 go func () {
@@ -229,7 +225,7 @@ func TestRealWaiterWaitWithTimeout(t *testing.T) {
229225 t .Errorf ("error creating temp file: %v" , err )
230226 }
231227 defer os .Remove (tmp .Name ())
232- ctx , cancel := context .WithTimeout (context . Background (), 1 * time .Millisecond )
228+ ctx , cancel := context .WithTimeout (t . Context (), 1 * time .Millisecond )
233229 defer cancel ()
234230 rw := realWaiter {}
235231 errCh := make (chan error )
@@ -262,7 +258,7 @@ func TestRealWaiterWaitContextWithBreakpointOnFailure(t *testing.T) {
262258 doneCh := make (chan struct {})
263259 go func () {
264260 // When breakpoint on failure is enabled skipError shouldn't be returned for a error waitfile
265- err := rw .setWaitPollingInterval (testWaitPollingInterval ).Wait (context . Background (), tmpFileName , false , true )
261+ err := rw .setWaitPollingInterval (testWaitPollingInterval ).Wait (t . Context (), tmpFileName , false , true )
266262 if err != nil {
267263 t .Errorf ("error waiting on tmp file %q" , tmp .Name ())
268264 }
@@ -288,7 +284,7 @@ func TestRealWaiterWaitContextWithErrorWaitfile(t *testing.T) {
288284 doneCh := make (chan struct {})
289285 go func () {
290286 // error of type skipError is returned after encountering a error waitfile
291- err := rw .setWaitPollingInterval (testWaitPollingInterval ).Wait (context . Background (), tmpFileName , false , false )
287+ err := rw .setWaitPollingInterval (testWaitPollingInterval ).Wait (t . Context (), tmpFileName , false , false )
292288 if err == nil {
293289 t .Errorf ("expected skipError upon encounter error waitfile" )
294290 }
@@ -317,7 +313,7 @@ func TestRealWaiterWaitContextWithContent(t *testing.T) {
317313 rw := realWaiter {}
318314 doneCh := make (chan struct {})
319315 go func () {
320- err := rw .setWaitPollingInterval (testWaitPollingInterval ).Wait (context . Background (), tmp .Name (), true , false )
316+ err := rw .setWaitPollingInterval (testWaitPollingInterval ).Wait (t . Context (), tmp .Name (), true , false )
321317 if err != nil {
322318 t .Errorf ("error waiting on tmp file %q" , tmp .Name ())
323319 }
@@ -345,21 +341,18 @@ func TestRealWaiterWaitContextMissingFile(t *testing.T) {
345341 }
346342 os .Remove (tmp .Name ())
347343 rw := realWaiter {}
348- doneCh := make (chan struct {} )
344+ errCh := make (chan error )
349345 go func () {
350- err := rw .setWaitPollingInterval (testWaitPollingInterval ).Wait (context .Background (), tmp .Name (), false , false )
351- if err != nil {
352- t .Errorf ("error waiting on tmp file %q" , tmp .Name ())
353- }
354- close (doneCh )
346+ err := rw .setWaitPollingInterval (testWaitPollingInterval ).Wait (t .Context (), tmp .Name (), false , false )
347+ errCh <- err
355348 }()
356349
357350 delay := time .NewTimer (2 * testWaitPollingInterval )
358351 select {
359352 case <- delay .C :
360353 // Success
361- case <- doneCh :
362- t .Errorf ("did not expect Wait() to have detected a file at path %q" , tmp .Name ())
354+ case err := <- errCh :
355+ t .Errorf ("did not expect Wait() to have detected a file at path %q, err: %v " , tmp .Name (), err )
363356 if ! delay .Stop () {
364357 <- delay .C
365358 }
0 commit comments