mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
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:
commit
014149d66e
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user