Skip to content

Commit

Permalink
Merge pull request ciao-project#350 from tpepper/unittests
Browse files Browse the repository at this point in the history
Unittests: race fixes
  • Loading branch information
markdryan authored Jul 18, 2016
2 parents dc6a720 + 7cf32c8 commit 57f6d19
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
14 changes: 5 additions & 9 deletions ciao-controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"net"
"os"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -732,22 +731,19 @@ func testStartWorkloadLaunchCNCI(t *testing.T, num int) (*testutil.SsntpTestClie
newTenant := uuid.Generate().String() // random ~= new tenant and thus triggers start of a CNCI

// trigger the START command flow, and await results
// NOTE: "instances" is shared with the go subroutine and we must
// insure consistency between parent and child processes
var instances []*types.Instance
instanceCh := make(chan []*types.Instance)

var wg sync.WaitGroup
wg.Add(1)
go func() {
instances, err = context.startWorkload(wls[0].ID, newTenant, 1, false, "")
instances, err := context.startWorkload(wls[0].ID, newTenant, 1, false, "")
if err != nil {
t.Fatal(err)
}

if len(instances) != 1 {
t.Fatalf("Wrong number of instances, expected 1, got %d", len(instances))
}
wg.Done()

instanceCh <- instances
}()

_, err = netClient.GetCmdChanResult(netClientCmdCh, ssntp.START)
Expand Down Expand Up @@ -794,7 +790,7 @@ func testStartWorkloadLaunchCNCI(t *testing.T, num int) (*testutil.SsntpTestClie
t.Fatalf("Did not get correct Instance ID, got %s, expected %s", result.InstanceUUID, tenantCNCI[0].InstanceID)
}

wg.Wait() // for "instances"
instances := <-instanceCh
if instances == nil {
t.Fatal("did not receive instance")
}
Expand Down
8 changes: 8 additions & 0 deletions ssntp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,15 @@ func (client *Client) handleSSNTPServer() {
break
}

client.status.Lock()
if client.status.status == ssntpClosed {
client.status.Unlock()
return
}
//insure new frame doesn't race with client.Close()
client.frameWg.Add(1)
client.status.Unlock()

go client.processSSNTPFrame(&frame)
}

Expand Down

0 comments on commit 57f6d19

Please sign in to comment.