Skip to content

Commit

Permalink
fix waiter test is flaky
Browse files Browse the repository at this point in the history
Signed-off-by: chengjoey <[email protected]>
  • Loading branch information
chengjoey authored and tekton-robot committed Oct 18, 2023
1 parent c98ce5b commit 4ec4587
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
22 changes: 11 additions & 11 deletions cmd/entrypoint/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,6 @@ func (rw *realWaiter) Wait(ctx context.Context, file string, expectContent bool,
return nil
}
for {
select {
case <-ctx.Done():
if errors.Is(ctx.Err(), context.Canceled) {
return entrypoint.ErrContextCanceled
}
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
return entrypoint.ErrContextDeadlineExceeded
}
return nil
case <-time.After(rw.waitPollingInterval):
}
if info, err := os.Stat(file); err == nil {
if !expectContent || info.Size() > 0 {
return nil
Expand All @@ -84,6 +73,17 @@ func (rw *realWaiter) Wait(ctx context.Context, file string, expectContent bool,
}
return skipError("error file present, bail and skip the step")
}
select {
case <-ctx.Done():
if errors.Is(ctx.Err(), context.Canceled) {
return entrypoint.ErrContextCanceled
}
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
return entrypoint.ErrContextDeadlineExceeded
}
return nil
case <-time.After(rw.waitPollingInterval):
}
}
}

Expand Down
10 changes: 4 additions & 6 deletions pkg/entrypoint/entrypointer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,15 @@ func TestEntrypointer(t *testing.T) {
}

if len(c.waitFiles) > 0 {
fw.Lock()
if fw.waited == nil {
t.Error("Wanted waited file, got nil")
} else if !reflect.DeepEqual(fw.waited, append(c.waitFiles, "/tekton/downward/cancel")) {
} else if !reflect.DeepEqual(fw.waited, c.waitFiles) {
t.Errorf("Waited for %v, want %v", fw.waited, c.waitFiles)
}
fw.Unlock()
}
fw.Lock()
if len(c.waitFiles) == 0 && len(fw.waited) != 1 {
if len(c.waitFiles) == 0 && fw.waited != nil {
t.Errorf("Waited for file when not required")
}
fw.Unlock()

wantArgs := append([]string{c.entrypoint}, c.args...)
if len(wantArgs) != 0 {
Expand Down Expand Up @@ -699,6 +695,8 @@ type fakeWaiter struct {
func (f *fakeWaiter) Wait(ctx context.Context, file string, _ bool, _ bool) error {
if file == pod.DownwardMountCancelFile && f.waitCancelDuration > 0 {
time.Sleep(f.waitCancelDuration)
} else if file == pod.DownwardMountCancelFile {
return nil
}
f.Lock()
f.waited = append(f.waited, file)
Expand Down

0 comments on commit 4ec4587

Please sign in to comment.