From 2c3cfed608083f5aef7e9b1a8f066254f0eaec44 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Fri, 13 Apr 2018 15:42:13 -0700 Subject: [PATCH] virtcontainers: mock: Properly end cc_proxy_mock goroutines Because of the bad design of the cc_proxy_mock go routine, we were leaving an infinite loop running into this go routine behind. This was consuming a lot of resources and it was obviously slowing down the tests being run in parallel. That's one of the reason we were hitting the 10 seconds timeout when running go tests. Fixes #208 Signed-off-by: Sebastien Boeuf --- virtcontainers/pkg/mock/cc_proxy_mock.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/virtcontainers/pkg/mock/cc_proxy_mock.go b/virtcontainers/pkg/mock/cc_proxy_mock.go index 3acee1a67..743e3ffa8 100644 --- a/virtcontainers/pkg/mock/cc_proxy_mock.go +++ b/virtcontainers/pkg/mock/cc_proxy_mock.go @@ -31,6 +31,8 @@ const testToken = "pF56IaDpuax6hihJ5PneB8JypqmOvjkqY-wKGVYqgIM=" // CCProxyMock is an object mocking clearcontainers Proxy type CCProxyMock struct { + sync.Mutex + t *testing.T wg sync.WaitGroup connectionPath string @@ -50,6 +52,8 @@ type CCProxyMock struct { Signal chan ShimSignal ShimDisconnected chan bool StdinReceived chan bool + + stopped bool } // NewCCProxyMock creates a hyperstart instance @@ -296,10 +300,19 @@ func (proxy *CCProxyMock) serve() { // Start invokes mock proxy instance to start listening. func (proxy *CCProxyMock) Start() { + proxy.stopped = false proxy.startListening() go func() { for { proxy.serve() + + proxy.Lock() + stopped := proxy.stopped + proxy.Unlock() + + if stopped { + break + } } }() } @@ -307,6 +320,10 @@ func (proxy *CCProxyMock) Start() { // Stop causes mock proxy instance to stop listening, // close connection to client and close all channels func (proxy *CCProxyMock) Stop() { + proxy.Lock() + proxy.stopped = true + proxy.Unlock() + proxy.listener.Close() if proxy.cl != nil {