summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTibor Vass <tiborvass@users.noreply.github.com>2020-09-16 07:28:27 -0700
committerGitHub <noreply@github.com>2020-09-16 07:28:27 -0700
commitbd33bbf0497b2327516dc799a5e541b720822a4c (patch)
tree48bdf60a587bd5484d8abfd753a1f02520efc84c
parent426396f438c75fa07fa82cee45c0b5d7bf70dc7f (diff)
parentec14dc44d13b7cca6f4ac85a094d4d54fe8afad6 (diff)
downloaddocker-bd33bbf0497b2327516dc799a5e541b720822a4c.tar.gz
Merge pull request #41314 from thaJeztah/19.03_backport_fix_racey_logger_testv19.03.13
[19.03 backport] test-fixes for flaky test: TestCheckCapacityAndRotate
-rw-r--r--daemon/logger/loggerutils/logfile_test.go31
1 files changed, 21 insertions, 10 deletions
diff --git a/daemon/logger/loggerutils/logfile_test.go b/daemon/logger/loggerutils/logfile_test.go
index d7ff34e242..f48e48cd27 100644
--- a/daemon/logger/loggerutils/logfile_test.go
+++ b/daemon/logger/loggerutils/logfile_test.go
@@ -6,6 +6,7 @@ import (
"io"
"io/ioutil"
"os"
+ "path/filepath"
"strings"
"testing"
"time"
@@ -14,6 +15,7 @@ import (
"github.com/docker/docker/pkg/pubsub"
"github.com/docker/docker/pkg/tailfile"
"gotest.tools/assert"
+ "gotest.tools/poll"
)
func TestTailFiles(t *testing.T) {
@@ -225,21 +227,15 @@ func TestCheckCapacityAndRotate(t *testing.T) {
defer l.Close()
assert.NilError(t, l.WriteLogEntry(&logger.Message{Line: []byte("hello world!")}))
-
- dStringer := dirStringer{dir}
-
_, err = os.Stat(f.Name() + ".1")
- assert.Assert(t, os.IsNotExist(err), dStringer)
+ assert.Assert(t, os.IsNotExist(err), dirStringer{dir})
assert.NilError(t, l.WriteLogEntry(&logger.Message{Line: []byte("hello world!")}))
- _, err = os.Stat(f.Name() + ".1")
- assert.NilError(t, err, dStringer)
+ poll.WaitOn(t, checkFileExists(f.Name()+".1.gz"), poll.WithDelay(time.Millisecond), poll.WithTimeout(30*time.Second))
assert.NilError(t, l.WriteLogEntry(&logger.Message{Line: []byte("hello world!")}))
- _, err = os.Stat(f.Name() + ".1")
- assert.NilError(t, err, dStringer)
- _, err = os.Stat(f.Name() + ".2.gz")
- assert.NilError(t, err, dStringer)
+ poll.WaitOn(t, checkFileExists(f.Name()+".1.gz"), poll.WithDelay(time.Millisecond), poll.WithTimeout(30*time.Second))
+ poll.WaitOn(t, checkFileExists(f.Name()+".2.gz"), poll.WithDelay(time.Millisecond), poll.WithTimeout(30*time.Second))
// Now let's simulate a failed rotation where the file was able to be closed but something else happened elsewhere
// down the line.
@@ -265,3 +261,18 @@ func (d dirStringer) String() string {
}
return s.String()
}
+
+func checkFileExists(name string) poll.Check {
+ return func(t poll.LogT) poll.Result {
+ _, err := os.Stat(name)
+ switch {
+ case err == nil:
+ return poll.Success()
+ case os.IsNotExist(err):
+ return poll.Continue("waiting for %s to exist", name)
+ default:
+ t.Logf("%s", dirStringer{filepath.Dir(name)})
+ return poll.Error(err)
+ }
+ }
+}