Merge pull request #121565 from srivastav-abhishek/logs_test_datarace

[FLAKE] Fixed UT pkg/kubelet/kuberuntime/logs/TestReadRotatedLog caused due to data race
This commit is contained in:
Kubernetes Prow Robot 2024-01-04 16:49:23 +01:00 committed by GitHub
commit 014149d66e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -219,7 +219,6 @@ func TestReadRotatedLog(t *testing.T) {
if err != nil {
assert.NoErrorf(t, err, "unable to create temp file")
}
stdoutBuf := &bytes.Buffer{}
stderrBuf := &bytes.Buffer{}
containerID := "fake-container-id"
@ -235,12 +234,13 @@ func TestReadRotatedLog(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Start to follow the container's log.
fileName := file.Name()
go func(ctx context.Context) {
podLogOptions := v1.PodLogOptions{
Follow: true,
}
opts := NewLogOptions(&podLogOptions, time.Now())
ReadLogs(ctx, file.Name(), containerID, opts, fakeRuntimeService, stdoutBuf, stderrBuf)
_ = ReadLogs(ctx, fileName, containerID, opts, fakeRuntimeService, stdoutBuf, stderrBuf)
}(ctx)
// log in stdout
@ -254,6 +254,7 @@ func TestReadRotatedLog(t *testing.T) {
// Write 10 lines to log file.
// Let ReadLogs start.
time.Sleep(50 * time.Millisecond)
for line := 0; line < 10; line++ {
// Write the first three lines to log file
now := time.Now().Format(types.RFC3339NanoLenient)