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

Commit

Permalink
functional: introduce a test TestUnitRestart
Browse files Browse the repository at this point in the history
A new functional test TestUnitRestart is also needed to verify that
the new command "fleetctl restart" works well.
  • Loading branch information
Dongsu Park committed Jul 6, 2016
1 parent c89aaf5 commit 0cef601
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions functional/unit_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ const (
)

var cleanCmd = map[string]string{
"submit": "destroy",
"load": "unload",
"start": "stop",
"submit": "destroy",
"load": "unload",
"start": "stop",
"restart": "stop",
}

// TestUnitRunnable is the simplest test possible, deplying a single-node
Expand Down Expand Up @@ -141,6 +142,41 @@ func TestUnitStart(t *testing.T) {
}
}

// TestUnitRestart checks if a unit becomes started and restarted successfully.
// First it starts a unit, and restarts the unit, verifies it's restarted.
func TestUnitRestart(t *testing.T) {
cluster, err := platform.NewNspawnCluster("smoke")
if err != nil {
t.Fatal(err)
}
defer cluster.Destroy(t)

m, err := cluster.CreateMember()
if err != nil {
t.Fatal(err)
}
_, err = cluster.WaitForNMachines(m, 1)
if err != nil {
t.Fatal(err)
}

numUnits := 3

// first start units before restarting them
unitFiles, err := launchUnitsCmd(cluster, m, "start", numUnits)
if err != nil {
t.Fatal(err)
}
if err := checkListUnits(cluster, m, "start", unitFiles, numUnits); err != nil {
t.Fatal(err)
}

// now restart
if err := unitStartCommon(cluster, m, "restart", numUnits); err != nil {
t.Fatal(err)
}
}

// TestUnitSubmitReplace() tests whether a command "fleetctl submit --replace
// hello.service" works or not.
func TestUnitSubmitReplace(t *testing.T) {
Expand Down Expand Up @@ -582,6 +618,8 @@ func checkListUnits(cl platform.Cluster, m platform.Member, cmd string, ufs []st
lenLists = len(lus)
break
case "start":
fallthrough
case "restart":
lus, err = waitForNUnitsStart(cl, m, nu)
lenLists = len(lus)
break
Expand Down Expand Up @@ -642,6 +680,8 @@ func waitForNUnitsCmd(cl platform.Cluster, m platform.Member, cmd string, nu int
_, err = waitForNUnitsLoad(cl, m, nu)
break
case "start":
fallthrough
case "restart":
_, err = waitForNUnitsStart(cl, m, nu)
break
default:
Expand Down

0 comments on commit 0cef601

Please sign in to comment.