From 1978866474bace489357dc644cbe2c642b12f74a Mon Sep 17 00:00:00 2001 From: Aldo Culquicondor Date: Tue, 11 Aug 2020 14:23:33 -0400 Subject: [PATCH] Improve running time of TestSchedulerWithVolumeBinding Only wait for finished binding or error, but not both Signed-off-by: Aldo Culquicondor Change-Id: I13d16e6c7c45c6527591aa05cc79fc5e96d47a68 --- pkg/scheduler/scheduler_test.go | 34 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/pkg/scheduler/scheduler_test.go b/pkg/scheduler/scheduler_test.go index 914185bd879..f2b6333fe35 100644 --- a/pkg/scheduler/scheduler_test.go +++ b/pkg/scheduler/scheduler_test.go @@ -953,28 +953,26 @@ func TestSchedulerWithVolumeBinding(t *testing.T) { t.Fatalf("scheduling timeout after %v", wait.ForeverTestTimeout) } stopFunc() - // Wait for scheduling to return an error + // Wait for scheduling to return an error or succeed binding. + var ( + gotErr error + gotBind *v1.Binding + ) select { - case err := <-errChan: - if item.expectError == nil || !reflect.DeepEqual(item.expectError.Error(), err.Error()) { - t.Errorf("err \nWANT=%+v,\nGOT=%+v", item.expectError, err) - } + case gotErr = <-errChan: + case gotBind = <-bindingChan: case <-time.After(chanTimeout): - if item.expectError != nil { - t.Errorf("did not receive error after %v", chanTimeout) - } + t.Fatalf("did not receive pod binding or error after %v", chanTimeout) } - - // Wait for pod to succeed binding - select { - case b := <-bindingChan: - if !reflect.DeepEqual(item.expectPodBind, b) { - t.Errorf("err \nWANT=%+v,\nGOT=%+v", item.expectPodBind, b) - } - case <-time.After(chanTimeout): - if item.expectPodBind != nil { - t.Errorf("did not receive pod binding after %v", chanTimeout) + if item.expectError != nil { + if gotErr == nil || item.expectError.Error() != gotErr.Error() { + t.Errorf("err \nWANT=%+v,\nGOT=%+v", item.expectError, gotErr) } + } else if gotErr != nil { + t.Errorf("err \nWANT=%+v,\nGOT=%+v", item.expectError, gotErr) + } + if !cmp.Equal(item.expectPodBind, gotBind) { + t.Errorf("err \nWANT=%+v,\nGOT=%+v", item.expectPodBind, gotBind) } if item.expectAssumeCalled != fakeVolumeBinder.AssumeCalled {