From a2dee1f6a07bf4890f17f8acc062ad249da60bc3 Mon Sep 17 00:00:00 2001 From: Peng Tao Date: Wed, 24 Mar 2021 18:20:12 +0800 Subject: [PATCH] runtime: fix vm factory UT failure We need to use different mocked socket otherwise they conflict with each other. Signed-off-by: Peng Tao --- src/runtime/virtcontainers/api_test.go | 6 +++++- src/runtime/virtcontainers/factory/factory_test.go | 12 ++++++++++-- .../virtcontainers/factory/template/template_test.go | 6 +++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/runtime/virtcontainers/api_test.go b/src/runtime/virtcontainers/api_test.go index 741db3b033..97bc1c4041 100644 --- a/src/runtime/virtcontainers/api_test.go +++ b/src/runtime/virtcontainers/api_test.go @@ -170,8 +170,12 @@ func TestCreateSandboxKataAgentSuccessful(t *testing.T) { config := newTestSandboxConfigKataAgent() + url, err := mock.GenerateKataMockHybridVSock() + assert.NoError(err) + MockHybridVSockPath = url + hybridVSockTTRPCMock := mock.HybridVSockTTRPCMock{} - err := hybridVSockTTRPCMock.Start(fmt.Sprintf("mock://%s", MockHybridVSockPath)) + err = hybridVSockTTRPCMock.Start(fmt.Sprintf("mock://%s", url)) assert.NoError(err) defer hybridVSockTTRPCMock.Stop() diff --git a/src/runtime/virtcontainers/factory/factory_test.go b/src/runtime/virtcontainers/factory/factory_test.go index 9ff9abcf49..91b47cf52c 100644 --- a/src/runtime/virtcontainers/factory/factory_test.go +++ b/src/runtime/virtcontainers/factory/factory_test.go @@ -59,8 +59,12 @@ func TestNewFactory(t *testing.T) { t.Skip(testDisabledAsNonRoot) } + url, err := mock.GenerateKataMockHybridVSock() + assert.NoError(err) + vc.MockHybridVSockPath = url + hybridVSockTTRPCMock := mock.HybridVSockTTRPCMock{} - err = hybridVSockTTRPCMock.Start(fmt.Sprintf("mock://%s", vc.MockHybridVSockPath)) + err = hybridVSockTTRPCMock.Start(fmt.Sprintf("mock://%s", url)) assert.NoError(err) defer hybridVSockTTRPCMock.Stop() @@ -173,8 +177,12 @@ func TestFactoryGetVM(t *testing.T) { t.Skip(testDisabledAsNonRoot) } + url, err := mock.GenerateKataMockHybridVSock() + assert.NoError(err) + vc.MockHybridVSockPath = url + hybridVSockTTRPCMock := mock.HybridVSockTTRPCMock{} - err = hybridVSockTTRPCMock.Start(fmt.Sprintf("mock://%s", vc.MockHybridVSockPath)) + err = hybridVSockTTRPCMock.Start(fmt.Sprintf("mock://%s", url)) assert.NoError(err) defer hybridVSockTTRPCMock.Stop() diff --git a/src/runtime/virtcontainers/factory/template/template_test.go b/src/runtime/virtcontainers/factory/template/template_test.go index 4eedc1655e..c7256218ca 100644 --- a/src/runtime/virtcontainers/factory/template/template_test.go +++ b/src/runtime/virtcontainers/factory/template/template_test.go @@ -47,8 +47,12 @@ func TestTemplateFactory(t *testing.T) { ctx := context.Background() + url, err := mock.GenerateKataMockHybridVSock() + assert.NoError(err) + vc.MockHybridVSockPath = url + hybridVSockTTRPCMock := mock.HybridVSockTTRPCMock{} - err = hybridVSockTTRPCMock.Start(fmt.Sprintf("mock://%s", vc.MockHybridVSockPath)) + err = hybridVSockTTRPCMock.Start(fmt.Sprintf("mock://%s", url)) assert.NoError(err) defer hybridVSockTTRPCMock.Stop()