mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-02-09 00:24:22 +01:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user