Merge pull request #58994 from RobertKrawitz/fake-runtime-start-race-condition-branch

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Race condition between listener and client in remote_runtime_test

Fix race condition in remote_runtime_test.
Fixes #58993
This commit is contained in:
Kubernetes Submit Queue 2018-01-31 20:31:50 -08:00 committed by GitHub
commit 465e925564
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

View File

@ -53,5 +53,6 @@ go_test(
"//pkg/kubelet/apis/cri/testing:go_default_library",
"//pkg/kubelet/remote/fake:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
"//vendor/github.com/stretchr/testify/require:go_default_library",
],
)

View File

@ -60,7 +60,8 @@ func (f *RemoteRuntime) Start(endpoint string) error {
return fmt.Errorf("failed to listen on %q: %v", endpoint, err)
}
return f.server.Serve(l)
go f.server.Serve(l)
return nil
}
// Stop stops the fake remote runtime.

View File

@ -21,6 +21,7 @@ import (
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
internalapi "k8s.io/kubernetes/pkg/kubelet/apis/cri"
apitest "k8s.io/kubernetes/pkg/kubelet/apis/cri/testing"
fakeremote "k8s.io/kubernetes/pkg/kubelet/remote/fake"
@ -35,17 +36,17 @@ const (
// Users should call fakeRuntime.Stop() to cleanup the server.
func createAndStartFakeRemoteRuntime(t *testing.T) (*fakeremote.RemoteRuntime, string) {
endpoint, err := fakeremote.GenerateEndpoint()
assert.NoError(t, err)
require.NoError(t, err)
fakeRuntime := fakeremote.NewFakeRemoteRuntime()
go fakeRuntime.Start(endpoint)
fakeRuntime.Start(endpoint)
return fakeRuntime, endpoint
}
func createRemoteRuntimeService(endpoint string, t *testing.T) internalapi.RuntimeService {
runtimeService, err := NewRemoteRuntimeService(endpoint, defaultConnectionTimeout)
assert.NoError(t, err)
require.NoError(t, err)
return runtimeService
}