From 5953a182cf06a339f3d45d1b67d526055181ff9e Mon Sep 17 00:00:00 2001 From: Jiaying Zhang Date: Mon, 25 Sep 2017 16:51:29 -0700 Subject: [PATCH] Fixes the flaky TestDevicePluginReRegistration. In the current test, there is a race that the new device plugin endpoint may not be added to the device plugin manager endpoints at the time when we call manager.Devices(). Added the checking and waiting for endpoint updates before calling manager.Devices() in the test. Tested: go test -race -count 500 k8s.io/kubernetes/pkg/kubelet/deviceplugin -run TestDevicePluginReRegistration -timeout 5h --- pkg/kubelet/deviceplugin/manager_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/kubelet/deviceplugin/manager_test.go b/pkg/kubelet/deviceplugin/manager_test.go index 354d33b0011..cdc43a0b255 100644 --- a/pkg/kubelet/deviceplugin/manager_test.go +++ b/pkg/kubelet/deviceplugin/manager_test.go @@ -70,6 +70,13 @@ func TestDevicePluginReRegistration(t *testing.T) { p1.Register(socketName, testResourceName) // Wait for the first callback to be issued. <-callbackChan + // Wait till the endpoint is added to the manager. + for i := 0; i < 20; i++ { + if len(m.Devices()) > 0 { + break + } + time.Sleep(1) + } devices := m.Devices() require.Equal(t, 2, len(devices[testResourceName]), "Devices are not updated.")