-
Notifications
You must be signed in to change notification settings - Fork 639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: logs updated on starting of a stopped container #3896
base: main
Are you sure you want to change the base?
Conversation
49019a2
to
ccb179d
Compare
@AkihiroSuda |
Signed-off-by: Shubharanshu Mahapatra <[email protected]>
ccb179d
to
e8fb6c4
Compare
), | ||
Setup: func(data test.Data, helpers test.Helpers) { | ||
cmd := helpers.Command("run", "-it", "--name", data.Identifier(), testutil.CommonImage) | ||
cmd.WithWrapper("unbuffer", "-p") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully, #3591 should be merged soon and remove the need to use unbuffer and DelayOnceReader.
return &test.Expected{ | ||
ExitCode: 0, | ||
Errors: []error{}, | ||
Output: test.All( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess test.All(
is unnecessary here as you only have one condition to test.
Expected: func(data test.Data, helpers test.Helpers) *test.Expected { | ||
return &test.Expected{ | ||
ExitCode: 0, | ||
Errors: []error{}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this line entirely.
), | ||
Setup: func(data test.Data, helpers test.Helpers) { | ||
cmd := helpers.Command("run", "-d", "--name", data.Identifier(), testutil.CommonImage, "sh", "-c", "while true; do echo foo; sleep 1; done") | ||
cmd.Run(&test.Expected{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can simplify to just: helpers.Ensure("run", "-d", "--name", data.Identifier(), testutil.CommonImage, "sh", "-c", "while true; do echo foo; sleep 1; done")
(that does the command and checks it is succesful)
initialFooCount := strings.Count(initialLogs, "foo") | ||
data.Set("initialFooCount", strconv.Itoa(initialFooCount)) | ||
helpers.Anyhow("start", data.Identifier()) | ||
time.Sleep(5 * time.Second) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You possibly want to replace helpers.Anyhow("start", data.Identifier())
with helpers.Ensure("start", data.Identifier())
to make sure it is succesful.
Also nerdtest.EnsureContainerStarted
should give you a more determistic way to achieve this without relying on an arbitrary wait.
data.Set("initialFooCount", strconv.Itoa(initialFooCount)) | ||
helpers.Anyhow("start", data.Identifier()) | ||
time.Sleep(5 * time.Second) | ||
cmd := helpers.Command("logs", data.Identifier()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return helpers.Command("logs", data.Identifier())
Expected: func(data test.Data, helpers test.Helpers) *test.Expected { | ||
return &test.Expected{ | ||
ExitCode: 0, | ||
Errors: []error{}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary.
return &test.Expected{ | ||
ExitCode: 0, | ||
Errors: []error{}, | ||
Output: test.All( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
func(stdout string, info string, t *testing.T) { | ||
finalLogsCount := strings.Count(stdout, "foo") | ||
initialFooCount, _ := strconv.Atoi(data.Get("initialFooCount")) | ||
assert.Assert(t, finalLogsCount > initialFooCount, "Expected 'foo' count to increase after restart") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert.Assert(t, finalLogsCount > initialFooCount, "Expected 'foo' count to increase after restart", info)
That will display context if it fails.
@@ -255,3 +258,97 @@ func TestTailFollowRotateLogs(t *testing.T) { | |||
} | |||
assert.Equal(t, true, len(tailLogs) > linesPerFile, logRun.Stderr()) | |||
} | |||
|
|||
func TestLogsWithStartContainer(t *testing.T) { | |||
if runtime.GOOS == "windows" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testCase.Require = test.Not(test.Windows)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if you do it at the test root, no need for it in the subtests.
@Shubhranshu153 I just have a batch of nits on the test. Btw, feedback on the test framework is highly welcome. Ideally, if we get #3591 in first, we can get rid of the added DelayOnceReaders here (and unbuffer). But anyhow, don't sweat it - I can clean that up afterwards if needed. |
Issue:
When we start a container that was running and stopped or exited, logs are not updated.
Steps to Reproduce:
step 1: Run and exit container
fix:
The pr fixes it by adding multiwriters to start of containers.