Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

chore(wait): log test timeout #2716

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 37 additions & 104 deletions wait/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import (
"time"

"github.com/docker/docker/api/types"
"github.com/stretchr/testify/require"
)

const logTimeout = time.Second

const loremIpsum = `Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
Donec a diam lectus.
Expand All @@ -28,9 +31,7 @@ func TestWaitForLog(t *testing.T) {
}
wg := NewLogStrategy("docker").WithStartupTimeout(100 * time.Microsecond)
err := wg.WaitUntilReady(context.Background(), target)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
})

t.Run("no regexp", func(t *testing.T) {
Expand All @@ -41,9 +42,7 @@ func TestWaitForLog(t *testing.T) {
// get all words that start with "ip", end with "m" and has a whitespace before the "ip"
wg := NewLogStrategy(`\sip[\w]+m`).WithStartupTimeout(100 * time.Microsecond).AsRegexp()
err := wg.WaitUntilReady(context.Background(), target)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
})
}

Expand All @@ -56,9 +55,7 @@ func TestWaitWithExactNumberOfOccurrences(t *testing.T) {
WithStartupTimeout(100 * time.Microsecond).
WithOccurrence(2)
err := wg.WaitUntilReady(context.Background(), target)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
})

t.Run("as regexp", func(t *testing.T) {
Expand All @@ -71,9 +68,7 @@ func TestWaitWithExactNumberOfOccurrences(t *testing.T) {
// one "ipsum mauris" and two "ipsum dolor sit am"
wg := NewLogStrategy(`ip(.*)m`).WithStartupTimeout(100 * time.Microsecond).AsRegexp().WithOccurrence(3)
err := wg.WaitUntilReady(context.Background(), target)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
})
}

Expand All @@ -83,12 +78,10 @@ func TestWaitWithExactNumberOfOccurrencesButItWillNeverHappen(t *testing.T) {
ReaderCloser: io.NopCloser(bytes.NewReader([]byte("kubernetes\r\ndocker"))),
}
wg := NewLogStrategy("containerd").
WithStartupTimeout(100 * time.Microsecond).
WithStartupTimeout(logTimeout).
WithOccurrence(2)
err := wg.WaitUntilReady(context.Background(), target)
if err == nil {
t.Fatal("expected error")
}
require.Error(t, err)
})

t.Run("as regexp", func(t *testing.T) {
Expand All @@ -100,9 +93,7 @@ func TestWaitWithExactNumberOfOccurrencesButItWillNeverHappen(t *testing.T) {
// there are only three occurrences matching
wg := NewLogStrategy(`do(.*)ck.+`).WithStartupTimeout(100 * time.Microsecond).AsRegexp().WithOccurrence(4)
err := wg.WaitUntilReady(context.Background(), target)
if err == nil {
t.Fatal("expected error")
}
require.Error(t, err)
})
}

Expand All @@ -112,12 +103,10 @@ func TestWaitShouldFailWithExactNumberOfOccurrences(t *testing.T) {
ReaderCloser: io.NopCloser(bytes.NewReader([]byte("kubernetes\r\ndocker"))),
}
wg := NewLogStrategy("docker").
WithStartupTimeout(100 * time.Microsecond).
WithStartupTimeout(logTimeout).
WithOccurrence(2)
err := wg.WaitUntilReady(context.Background(), target)
if err == nil {
t.Fatal("expected error")
}
require.Error(t, err)
})

t.Run("as regexp", func(t *testing.T) {
Expand All @@ -129,9 +118,7 @@ func TestWaitShouldFailWithExactNumberOfOccurrences(t *testing.T) {
// there are only one occurrence matching
wg := NewLogStrategy(`^Mae[\w]?enas\s`).WithStartupTimeout(100 * time.Microsecond).AsRegexp().WithOccurrence(2)
err := wg.WaitUntilReady(context.Background(), target)
if err == nil {
t.Fatal("expected error")
}
require.Error(t, err)
})
}

Expand All @@ -148,37 +135,19 @@ func TestWaitForLogFailsDueToOOMKilledContainer(t *testing.T) {
}

t.Run("no regexp", func(t *testing.T) {
wg := ForLog("docker").
WithStartupTimeout(100 * time.Microsecond)

{
err := wg.WaitUntilReady(context.Background(), target)
if err == nil {
t.Fatal("no error")
}
wg := ForLog("docker").WithStartupTimeout(logTimeout)

expected := "container crashed with out-of-memory (OOMKilled)"
if err.Error() != expected {
t.Fatalf("expected %q, got %q", expected, err.Error())
}
}
err := wg.WaitUntilReady(context.Background(), target)
expected := "container crashed with out-of-memory (OOMKilled)"
require.EqualError(t, err, expected)
})

t.Run("as regexp", func(t *testing.T) {
wg := ForLog("docker").
WithStartupTimeout(100 * time.Microsecond).AsRegexp()

{
err := wg.WaitUntilReady(context.Background(), target)
if err == nil {
t.Fatal("no error")
}
wg := ForLog("docker").WithStartupTimeout(logTimeout).AsRegexp()

expected := "container crashed with out-of-memory (OOMKilled)"
if err.Error() != expected {
t.Fatalf("expected %q, got %q", expected, err.Error())
}
}
err := wg.WaitUntilReady(context.Background(), target)
expected := "container crashed with out-of-memory (OOMKilled)"
require.EqualError(t, err, expected)
})
}

Expand All @@ -196,37 +165,19 @@ func TestWaitForLogFailsDueToExitedContainer(t *testing.T) {
}

t.Run("no regexp", func(t *testing.T) {
wg := ForLog("docker").
WithStartupTimeout(100 * time.Microsecond)
wg := ForLog("docker").WithStartupTimeout(logTimeout)

{
err := wg.WaitUntilReady(context.Background(), target)
if err == nil {
t.Fatal("no error")
}

expected := "container exited with code 1"
if err.Error() != expected {
t.Fatalf("expected %q, got %q", expected, err.Error())
}
}
err := wg.WaitUntilReady(context.Background(), target)
expected := "container exited with code 1"
require.EqualError(t, err, expected)
})

t.Run("as regexp", func(t *testing.T) {
wg := ForLog("docker").
WithStartupTimeout(100 * time.Microsecond).AsRegexp()

{
err := wg.WaitUntilReady(context.Background(), target)
if err == nil {
t.Fatal("no error")
}
wg := ForLog("docker").WithStartupTimeout(logTimeout).AsRegexp()

expected := "container exited with code 1"
if err.Error() != expected {
t.Fatalf("expected %q, got %q", expected, err.Error())
}
}
err := wg.WaitUntilReady(context.Background(), target)
expected := "container exited with code 1"
require.EqualError(t, err, expected)
})
}

Expand All @@ -243,36 +194,18 @@ func TestWaitForLogFailsDueToUnexpectedContainerStatus(t *testing.T) {
}

t.Run("no regexp", func(t *testing.T) {
wg := ForLog("docker").
WithStartupTimeout(100 * time.Microsecond)

{
err := wg.WaitUntilReady(context.Background(), target)
if err == nil {
t.Fatal("no error")
}
wg := ForLog("docker").WithStartupTimeout(logTimeout)

expected := "unexpected container status \"dead\""
if err.Error() != expected {
t.Fatalf("expected %q, got %q", expected, err.Error())
}
}
err := wg.WaitUntilReady(context.Background(), target)
expected := "unexpected container status \"dead\""
require.EqualError(t, err, expected)
})

t.Run("as regexp", func(t *testing.T) {
wg := ForLog("docker").
WithStartupTimeout(100 * time.Microsecond).AsRegexp()
wg := ForLog("docker").WithStartupTimeout(logTimeout).AsRegexp()

{
err := wg.WaitUntilReady(context.Background(), target)
if err == nil {
t.Fatal("no error")
}

expected := "unexpected container status \"dead\""
if err.Error() != expected {
t.Fatalf("expected %q, got %q", expected, err.Error())
}
}
err := wg.WaitUntilReady(context.Background(), target)
expected := "unexpected container status \"dead\""
require.EqualError(t, err, expected)
})
}