mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 02:09:56 +00:00
add test for triggering race condition
This commit is contained in:
parent
ab1807f2bc
commit
bb3fe633b4
@ -26,6 +26,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -3220,3 +3221,33 @@ func TestSortPodIPs(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConvertToAPIContainerStatusesDataRace(t *testing.T) {
|
||||||
|
pod := podWithUIDNameNs("12345", "test-pod", "test-namespace")
|
||||||
|
|
||||||
|
testTimestamp := time.Unix(123456789, 987654321)
|
||||||
|
|
||||||
|
criStatus := &kubecontainer.PodStatus{
|
||||||
|
ID: pod.UID,
|
||||||
|
Name: pod.Name,
|
||||||
|
Namespace: pod.Namespace,
|
||||||
|
ContainerStatuses: []*kubecontainer.Status{
|
||||||
|
{Name: "containerA", CreatedAt: testTimestamp},
|
||||||
|
{Name: "containerB", CreatedAt: testTimestamp.Add(1)},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
testKubelet := newTestKubelet(t, false)
|
||||||
|
defer testKubelet.Cleanup()
|
||||||
|
kl := testKubelet.kubelet
|
||||||
|
|
||||||
|
// convertToAPIContainerStatuses is purely transformative and shouldn't alter the state of the kubelet
|
||||||
|
// as there are no synchronisation events in that function (no locks, no channels, ...) each test routine
|
||||||
|
// should have its own vector clock increased independently. Golang race detector uses pure happens-before
|
||||||
|
// detection, so would catch a race condition consistently, despite only spawning 2 goroutines
|
||||||
|
for i := 0; i < 2; i++ {
|
||||||
|
go func() {
|
||||||
|
kl.convertToAPIContainerStatuses(pod, criStatus, []v1.ContainerStatus{}, []v1.Container{}, false, false)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user