Skip to content

Commit 12daca5

Browse files
committed
Fix intermittent test failures on Windows CIs
Signed-off-by: Kirtana Ashok <[email protected]>
1 parent 6af7c07 commit 12daca5

3 files changed

Lines changed: 37 additions & 35 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,10 @@ jobs:
307307
run: mingw32-make.exe integration
308308
- run: if [ -f *-gotest.json ]; then echo '# Integration 1' >> $GITHUB_STEP_SUMMARY; teststat -markdown *-gotest.json >> $GITHUB_STEP_SUMMARY; fi
309309
if: always()
310-
- run: script/test/test2annotation.sh ${TESTFILE}
310+
- run: script/test/test2annotation.sh "$TESTFILE"
311311
env:
312312
TESTFILE: ${{github.workspace}}/test-integration-serial-gotest.json
313-
if: always()
313+
if: success()
314314

315315
# Run the integration suite a second time. See discussion in github.com/containerd/containerd/pull/1759
316316
- name: Integration 2
@@ -323,10 +323,10 @@ jobs:
323323
run: mingw32-make.exe integration
324324
- run: if [ -f *-gotest.json ]; then echo '# Integration 2' >> $GITHUB_STEP_SUMMARY; teststat -markdown *-gotest.json >> $GITHUB_STEP_SUMMARY; fi
325325
if: always()
326-
- run: script/test/test2annotation.sh ${TESTFILE}
326+
- run: script/test/test2annotation.sh "$TESTFILE"
327327
env:
328328
TESTFILE: ${{github.workspace}}/test-integration-parallel-gotest.json
329-
if: always()
329+
if: success()
330330

331331
- name: CRI Integration Test
332332
env:

core/content/testsuite/testsuite.go

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,15 @@ func checkRefNotAvailable(ctx context.Context, t *testing.T, cs content.Store, r
363363
}
364364
}
365365

366+
func discardWriter(t *testing.T, w content.Writer) {
367+
if err := w.Truncate(0); err != nil {
368+
t.Errorf("failed to truncate writer: %+v", err)
369+
}
370+
if err := w.Close(); err != nil {
371+
t.Errorf("failed to close writer: %+v", err)
372+
}
373+
}
374+
366375
func checkCommitErrorState(ctx context.Context, t *testing.T, cs content.Store) {
367376
c1, d1 := createContent(256)
368377
_, d2 := createContent(256)
@@ -376,9 +385,7 @@ func checkCommitErrorState(ctx context.Context, t *testing.T, cs content.Store)
376385
t.Fatal(err)
377386
}
378387
if _, err := w.Write(c1); err != nil {
379-
if err := w.Close(); err != nil {
380-
t.Errorf("Close error: %+v", err)
381-
}
388+
discardWriter(t, w)
382389
t.Fatal(err)
383390
}
384391

@@ -389,9 +396,7 @@ func checkCommitErrorState(ctx context.Context, t *testing.T, cs content.Store)
389396
if err == nil {
390397
t.Fatalf("Expected already exists error")
391398
} else if !errdefs.IsAlreadyExists(err) {
392-
if err := w.Close(); err != nil {
393-
t.Errorf("Close error: %+v", err)
394-
}
399+
discardWriter(t, w)
395400
t.Fatalf("Unexpected error: %+v", err)
396401
}
397402

@@ -403,9 +408,7 @@ func checkCommitErrorState(ctx context.Context, t *testing.T, cs content.Store)
403408
checkRefNotAvailable(ctx, t, cs, ref)
404409

405410
if _, err := w.Write(c1); err != nil {
406-
if err := w.Close(); err != nil {
407-
t.Errorf("close error: %+v", err)
408-
}
411+
discardWriter(t, w)
409412
t.Fatal(err)
410413
}
411414

@@ -414,9 +417,7 @@ func checkCommitErrorState(ctx context.Context, t *testing.T, cs content.Store)
414417
if err == nil {
415418
t.Fatalf("Expected already exists error")
416419
} else if !errdefs.IsAlreadyExists(err) {
417-
if err := w.Close(); err != nil {
418-
t.Errorf("Close error: %+v", err)
419-
}
420+
discardWriter(t, w)
420421
t.Fatalf("Unexpected error: %+v", err)
421422
}
422423
w.Close()
@@ -429,9 +430,7 @@ func checkCommitErrorState(ctx context.Context, t *testing.T, cs content.Store)
429430
checkRefNotAvailable(ctx, t, cs, ref)
430431

431432
if _, err := w.Write(append(c1, []byte("more")...)); err != nil {
432-
if err := w.Close(); err != nil {
433-
t.Errorf("close error: %+v", err)
434-
}
433+
discardWriter(t, w)
435434
t.Fatal(err)
436435
}
437436

@@ -440,10 +439,11 @@ func checkCommitErrorState(ctx context.Context, t *testing.T, cs content.Store)
440439
if err == nil {
441440
t.Fatalf("Expected error from wrong digest")
442441
} else if !errdefs.IsFailedPrecondition(err) {
443-
t.Errorf("Unexpected error: %+v", err)
442+
discardWriter(t, w)
443+
t.Fatalf("Unexpected error: %+v", err)
444444
}
445-
446445
w.Close()
446+
447447
w, err = content.OpenWriter(ctx, cs, content.WithRef(ref))
448448
if err != nil {
449449
t.Fatal(err)
@@ -456,10 +456,11 @@ func checkCommitErrorState(ctx context.Context, t *testing.T, cs content.Store)
456456
if err == nil {
457457
t.Fatalf("Expected error from wrong size")
458458
} else if !errdefs.IsFailedPrecondition(err) {
459-
t.Errorf("Unexpected error: %+v", err)
459+
discardWriter(t, w)
460+
t.Fatalf("Unexpected error: %+v", err)
460461
}
461-
462462
w.Close()
463+
463464
w, err = content.OpenWriter(ctx, cs, content.WithRef(ref))
464465
if err != nil {
465466
t.Fatal(err)
@@ -469,23 +470,19 @@ func checkCommitErrorState(ctx context.Context, t *testing.T, cs content.Store)
469470

470471
// Now expect commit to succeed
471472
if err := w.Commit(ctx, int64(len(c1))+4, ""); err != nil {
472-
if err := w.Close(); err != nil {
473-
t.Errorf("close error: %+v", err)
474-
}
473+
discardWriter(t, w)
475474
t.Fatalf("Failed to commit: %+v", err)
476475
}
477-
478476
w.Close()
477+
479478
// Create another writer with same reference
480479
w, err = content.OpenWriter(ctx, cs, content.WithRef(ref))
481480
if err != nil {
482481
t.Fatalf("Failed to open writer: %+v", err)
483482
}
484483

485484
if _, err := w.Write(c1); err != nil {
486-
if err := w.Close(); err != nil {
487-
t.Errorf("close error: %+v", err)
488-
}
485+
discardWriter(t, w)
489486
t.Fatal(err)
490487
}
491488

@@ -496,20 +493,21 @@ func checkCommitErrorState(ctx context.Context, t *testing.T, cs content.Store)
496493
if err == nil {
497494
t.Fatalf("Expected already exists error")
498495
} else if !errdefs.IsAlreadyExists(err) {
499-
if err := w.Close(); err != nil {
500-
t.Errorf("close error: %+v", err)
501-
}
496+
discardWriter(t, w)
502497
t.Fatalf("Unexpected error: %+v", err)
503498
}
504-
505499
w.Close()
500+
506501
w, err = content.OpenWriter(ctx, cs, content.WithRef(ref))
507502
if err != nil {
508503
t.Fatal(err)
509504
}
510505

511506
checkRefNotAvailable(ctx, t, cs, ref)
512507

508+
if err := w.Truncate(0); err != nil {
509+
t.Fatalf("failed to truncate writer: %+v", err)
510+
}
513511
if err := w.Close(); err != nil {
514512
t.Fatalf("Close failed: %+v", err)
515513
}
@@ -519,6 +517,9 @@ func checkCommitErrorState(ctx context.Context, t *testing.T, cs content.Store)
519517
if err != nil {
520518
t.Fatalf("Failed to open writer: %+v", err)
521519
}
520+
if err := w.Truncate(0); err != nil {
521+
t.Fatalf("failed to truncate writer: %+v", err)
522+
}
522523
if err := w.Close(); err != nil {
523524
t.Fatalf("Close failed: %+v", err)
524525
}

internal/cri/executil/exec_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ package executil
3434

3535
import (
3636
"context"
37+
"errors"
3738
"io"
3839
"os"
3940
osexec "os/exec"
@@ -158,7 +159,7 @@ func TestTimeout(t *testing.T) {
158159
defer cancel()
159160

160161
err := exec.CommandContext(ctx, "sleep", "2").Run()
161-
if err != context.DeadlineExceeded {
162+
if !errors.Is(ctx.Err(), context.DeadlineExceeded) {
162163
t.Errorf("expected %v but got %v", context.DeadlineExceeded, err)
163164
}
164165
}

0 commit comments

Comments
 (0)