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 <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2018-04-13 15:42:13 -07:00
parent feade98473
commit 2c3cfed608

View File

@@ -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 {