Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #437 from tpepper/unittests
Browse files Browse the repository at this point in the history
Unittests: locking fixes and race hunting
  • Loading branch information
Samuel Ortiz authored Aug 7, 2016
2 parents 56930ea + e9e316b commit 981bb66
Show file tree
Hide file tree
Showing 12 changed files with 317 additions and 67 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ script:
- go list ./... | grep -v github.com/01org/ciao/vendor | xargs go list -f '{{.Dir}}' | xargs gofmt -s -l | wc -l | xargs -I % bash -c "test % -eq 0"
- sudo mkdir -p /var/lib/ciao/instances
- sudo chmod 0777 /var/lib/ciao/instances
- test-cases -v -timeout 9 -text -coverprofile /tmp/cover.out -short github.com/01org/ciao/ciao-launcher github.com/01org/ciao/ciao-scheduler github.com/01org/ciao/ciao-controller/... github.com/01org/ciao/payloads github.com/01org/ciao/configuration github.com/01org/ciao/testutil github.com/01org/ciao/ssntp/uuid
- export GOROOT=`go env GOROOT` && sudo -E PATH=$PATH:$GOROOT/bin $GOPATH/bin/test-cases -v -timeout 9 -text -coverprofile /tmp/cover.out -append-profile github.com/01org/ciao/ssntp
- export GOROOT=`go env GOROOT` && export SNNET_ENV=198.51.100.0/24 && sudo -E PATH=$PATH:$GOROOT/bin $GOPATH/bin/test-cases -v -timeout 9 -text -short -tags travis -coverprofile /tmp/cover.out -append-profile github.com/01org/ciao/networking/libsnnet
- test-cases -v -timeout 9 -text -coverprofile /tmp/cover.out -short github.com/01org/ciao/ciao-controller/...
- test-cases -v -timeout 9 -text -coverprofile /tmp/cover.out -append-profile -short -race github.com/01org/ciao/ciao-launcher github.com/01org/ciao/ciao-scheduler github.com/01org/ciao/payloads github.com/01org/ciao/configuration github.com/01org/ciao/testutil github.com/01org/ciao/ssntp/uuid
- export GOROOT=`go env GOROOT` && sudo -E PATH=$PATH:$GOROOT/bin $GOPATH/bin/test-cases -v -timeout 9 -text -coverprofile /tmp/cover.out -append-profile -race github.com/01org/ciao/ssntp
- export GOROOT=`go env GOROOT` && export SNNET_ENV=198.51.100.0/24 && sudo -E PATH=$PATH:$GOROOT/bin $GOPATH/bin/test-cases -v -timeout 9 -text -short -tags travis -coverprofile /tmp/cover.out -append-profile -race github.com/01org/ciao/networking/libsnnet

after_success:
- $GOPATH/bin/goveralls -service=travis-ci -coverprofile=/tmp/cover.out
Expand Down
14 changes: 7 additions & 7 deletions ciao-controller/compute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func testDeleteServer(t *testing.T, httpExpectedStatus int, httpExpectedErrorSta
if err != nil {
t.Fatal(err)
}
defer client.Ssntp.Close()
defer client.Shutdown()

tURL := testutil.ComputeURL + "/v2.1/" + tenant.ID + "/servers/"

Expand Down Expand Up @@ -337,7 +337,7 @@ func testServersActionStart(t *testing.T, httpExpectedStatus int, validToken boo
if err != nil {
t.Fatal(err)
}
defer client.Ssntp.Close()
defer client.Shutdown()

servers := testCreateServer(t, 1)
if servers.TotalServers != 1 {
Expand Down Expand Up @@ -397,7 +397,7 @@ func testServersActionStop(t *testing.T, httpExpectedStatus int, action string)
if err != nil {
t.Fatal(err)
}
defer client.Ssntp.Close()
defer client.Shutdown()

servers := testCreateServer(t, 1)
if servers.TotalServers != 1 {
Expand Down Expand Up @@ -446,7 +446,7 @@ func testServerActionStop(t *testing.T, httpExpectedStatus int, validToken bool)
if err != nil {
t.Fatal(err)
}
defer client.Ssntp.Close()
defer client.Shutdown()

servers := testCreateServer(t, 1)
if servers.TotalServers != 1 {
Expand Down Expand Up @@ -483,7 +483,7 @@ func TestServerActionStart(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer client.Ssntp.Close()
defer client.Shutdown()

servers := testCreateServer(t, 1)
if servers.TotalServers != 1 {
Expand Down Expand Up @@ -1124,7 +1124,7 @@ func testListTraces(t *testing.T, httpExpectedStatus int, validToken bool) {
var expected payloads.CiaoTracesSummary

client := testStartTracedWorkload(t)
defer client.Ssntp.Close()
defer client.Shutdown()

sendTraceReportEvent(client, t)

Expand Down Expand Up @@ -1246,7 +1246,7 @@ func TestClearEventsInvalidToken(t *testing.T) {

func testTraceData(t *testing.T, httpExpectedStatus int, validToken bool) {
client := testStartTracedWorkload(t)
defer client.Ssntp.Close()
defer client.Shutdown()

sendTraceReportEvent(client, t)

Expand Down
44 changes: 22 additions & 22 deletions ciao-controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,17 @@ func TestStartWorkload(t *testing.T) {
var reason payloads.StartFailureReason

client, _ := testStartWorkload(t, 1, false, reason)
defer client.Ssntp.Close()
defer client.Shutdown()
}

func TestStartTracedWorkload(t *testing.T) {
client := testStartTracedWorkload(t)
defer client.Ssntp.Close()
defer client.Shutdown()
}

func TestStartWorkloadLaunchCNCI(t *testing.T) {
netClient, instances := testStartWorkloadLaunchCNCI(t, 1)
defer netClient.Ssntp.Close()
defer netClient.Shutdown()

id := instances[0].TenantID

Expand Down Expand Up @@ -293,7 +293,7 @@ func TestDeleteInstance(t *testing.T) {
var reason payloads.StartFailureReason

client, instances := testStartWorkload(t, 1, false, reason)
defer client.Ssntp.Close()
defer client.Shutdown()

sendStatsCmd(client, t)

Expand All @@ -319,7 +319,7 @@ func TestStopInstance(t *testing.T) {
var reason payloads.StartFailureReason

client, instances := testStartWorkload(t, 1, false, reason)
defer client.Ssntp.Close()
defer client.Shutdown()

sendStatsCmd(client, t)

Expand All @@ -345,7 +345,7 @@ func TestRestartInstance(t *testing.T) {
var reason payloads.StartFailureReason

client, instances := testStartWorkload(t, 1, false, reason)
defer client.Ssntp.Close()
defer client.Shutdown()

time.Sleep(1 * time.Second)

Expand Down Expand Up @@ -400,7 +400,7 @@ func TestEvacuateNode(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer client.Ssntp.Close()
defer client.Shutdown()

serverCh := server.AddCmdChan(ssntp.EVACUATE)

Expand All @@ -424,7 +424,7 @@ func TestInstanceDeletedEvent(t *testing.T) {
var reason payloads.StartFailureReason

client, instances := testStartWorkload(t, 1, false, reason)
defer client.Ssntp.Close()
defer client.Shutdown()

sendStatsCmd(client, t)

Expand Down Expand Up @@ -467,7 +467,7 @@ func TestStartFailure(t *testing.T) {
reason := payloads.FullCloud

client, _ := testStartWorkload(t, 1, true, reason)
defer client.Ssntp.Close()
defer client.Shutdown()

// since we had a start failure, we should confirm that the
// instance is no longer pending in the database
Expand All @@ -479,7 +479,7 @@ func TestStopFailure(t *testing.T) {
var reason payloads.StartFailureReason

client, instances := testStartWorkload(t, 1, false, reason)
defer client.Ssntp.Close()
defer client.Shutdown()

client.StopFail = true
client.StopFailReason = payloads.StopNoInstance
Expand Down Expand Up @@ -527,7 +527,7 @@ func TestRestartFailure(t *testing.T) {
var reason payloads.StartFailureReason

client, instances := testStartWorkload(t, 1, false, reason)
defer client.Ssntp.Close()
defer client.Shutdown()

client.RestartFail = true
client.RestartFailReason = payloads.RestartLaunchFailure
Expand Down Expand Up @@ -601,10 +601,10 @@ func TestNoNetwork(t *testing.T) {
var reason payloads.StartFailureReason

client, _ := testStartWorkload(t, 1, false, reason)
defer client.Ssntp.Close()
defer client.Shutdown()
}

// NOTE: the caller is responsible for calling Ssntp.Close() on the *SsntpTestClient
// NOTE: the caller is responsible for calling Shutdown() on the *SsntpTestClient
func testStartTracedWorkload(t *testing.T) *testutil.SsntpTestClient {
tenant, err := addTestTenant()
if err != nil {
Expand All @@ -616,7 +616,7 @@ func testStartTracedWorkload(t *testing.T) *testutil.SsntpTestClient {
t.Fatal(err)
}
// caller of TestStartTracedWorkload() owns doing the close
//defer client.Ssntp.Close()
//defer client.Shutdown()

wls, err := context.ds.GetWorkloads()
if err != nil {
Expand Down Expand Up @@ -652,7 +652,7 @@ func testStartTracedWorkload(t *testing.T) *testutil.SsntpTestClient {
return client
}

// NOTE: the caller is responsible for calling Ssntp.Close() on the *SsntpTestClient
// NOTE: the caller is responsible for calling Shutdown() on the *SsntpTestClient
func testStartWorkload(t *testing.T, num int, fail bool, reason payloads.StartFailureReason) (*testutil.SsntpTestClient, []*types.Instance) {
tenant, err := addTestTenant()
if err != nil {
Expand All @@ -664,7 +664,7 @@ func testStartWorkload(t *testing.T, num int, fail bool, reason payloads.StartFa
t.Fatal(err)
}
// caller of TestStartWorkload() owns doing the close
//defer client.Ssntp.Close()
//defer client.Shutdown()

wls, err := context.ds.GetWorkloads()
if err != nil {
Expand Down Expand Up @@ -708,14 +708,14 @@ func testStartWorkload(t *testing.T, num int, fail bool, reason payloads.StartFa
return client, instances
}

// NOTE: the caller is responsible for calling Ssntp.Close() on the *SsntpTestClient
// NOTE: the caller is responsible for calling Shutdown() on the *SsntpTestClient
func testStartWorkloadLaunchCNCI(t *testing.T, num int) (*testutil.SsntpTestClient, []*types.Instance) {
netClient, err := testutil.NewSsntpTestClientConnection("StartWorkloadLaunchCNCI", ssntp.NETAGENT, testutil.NetAgentUUID)
if err != nil {
t.Fatal(err)
}
// caller of testStartWorkloadLaunchCNCI() owns doing the close
//defer netClient.Ssntp.Close()
//defer netClient.Shutdown()

wls, err := context.ds.GetWorkloads()
if err != nil {
Expand Down Expand Up @@ -784,7 +784,7 @@ func testStartWorkloadLaunchCNCI(t *testing.T, num int) (*testutil.SsntpTestClie
}

// shutdown the test CNCI client
cnciClient.Ssntp.Close()
cnciClient.Shutdown()

if result.InstanceUUID != tenantCNCI[0].InstanceID {
t.Fatalf("Did not get correct Instance ID, got %s, expected %s", result.InstanceUUID, tenantCNCI[0].InstanceID)
Expand All @@ -800,13 +800,13 @@ func testStartWorkloadLaunchCNCI(t *testing.T, num int) (*testutil.SsntpTestClie

var testClients []*testutil.SsntpTestClient
var context *controller
var server testutil.SsntpTestServer
var server *testutil.SsntpTestServer

func TestMain(m *testing.M) {
flag.Parse()

// create fake ssntp server
testutil.StartTestServer(&server)
server = testutil.StartTestServer()

context = new(controller)
context.ds = new(datastore.Datastore)
Expand Down Expand Up @@ -863,7 +863,7 @@ func TestMain(m *testing.M) {
context.client.Disconnect()
context.ds.Exit()
id.Close()
server.Ssntp.Stop()
server.Shutdown()

os.Remove("./ciao-controller-test.db")
os.Remove("./ciao-controller-test.db-shm")
Expand Down
5 changes: 5 additions & 0 deletions test-cases/test-cases.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ var coverageRegexp *regexp.Regexp
var cssPath string
var textOutput bool
var short bool
var race bool
var tags string
var colour bool
var coverProfile string
Expand All @@ -153,6 +154,7 @@ func init() {
flag.StringVar(&cssPath, "css", "", "Full path to CSS file")
flag.BoolVar(&textOutput, "text", false, "Output text instead of HTML")
flag.BoolVar(&short, "short", false, "If true -short is passed to go test")
flag.BoolVar(&race, "race", false, "If true -race is passed to go test")
flag.StringVar(&tags, "tags", "", "Build tags to pass to go test")
flag.StringVar(&coverProfile, "coverprofile", "", "Path of coverage profile to be generated")
flag.BoolVar(&appendProfile, "append-profile", false, "Append generated coverage profiles an existing file")
Expand Down Expand Up @@ -382,6 +384,9 @@ func runPackageTests(p *PackageTests, coverFile string, errorOutput *bytes.Buffe
if short {
args = append(args, "-short")
}
if race {
args = append(args, "-race")
}
if tags != "" {
args = append(args, "-tags", tags)
}
Expand Down
Loading

0 comments on commit 981bb66

Please sign in to comment.