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

Commit

Permalink
functional: rename a function and remove an unnecessary helper
Browse files Browse the repository at this point in the history
Rename WaitForNAllUnits() into WaitForNUnits().
Remove waitForActiveUnitsReplaceCmds(), as it's already covered by
WaitForNUnits().
  • Loading branch information
Dongsu Park committed Mar 22, 2016
1 parent 8a22f07 commit cd3a786
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 41 deletions.
2 changes: 1 addition & 1 deletion functional/platform/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Cluster interface {
// client operations
Fleetctl(m Member, args ...string) (string, string, error)
FleetctlWithInput(m Member, input string, args ...string) (string, string, error)
WaitForNAllUnits(Member, int) error
WaitForNUnits(Member, int) error
WaitForNActiveUnits(Member, int) (map[string][]util.UnitState, error)
WaitForNMachines(Member, int) ([]string, error)
}
Expand Down
2 changes: 1 addition & 1 deletion functional/platform/nspawn.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (nc *nspawnCluster) FleetctlWithInput(m Member, input string, args ...strin
return util.RunFleetctlWithInput(input, args...)
}

func (nc *nspawnCluster) WaitForNAllUnits(m Member, count int) error {
func (nc *nspawnCluster) WaitForNUnits(m Member, count int) error {
timeout := 15 * time.Second
alarm := time.After(timeout)

Expand Down
41 changes: 2 additions & 39 deletions functional/unit_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,10 @@ func replaceUnitCommon(cmd string) error {
return fmt.Errorf("Failed to destroy unit: %v", err)
}

if err := cluster.WaitForNAllUnits(m, 0); err != nil {
if err := cluster.WaitForNUnits(m, 0); err != nil {
return fmt.Errorf("Failed to get every unit to be cleaned up: %v", err)
}

if err := waitForActiveUnitsReplaceCmds(cluster, m, cmd, 0); err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -486,16 +482,12 @@ func replaceUnitMultiple(cmd string, n int) error {
os.Remove(curHelloService)
}

if err := cluster.WaitForNAllUnits(m, 0); err != nil {
if err := cluster.WaitForNUnits(m, 0); err != nil {
return fmt.Errorf("Failed to get every unit to be cleaned up: %v", err)
}

os.Remove(tmpFixtures)

if err := waitForActiveUnitsReplaceCmds(cluster, m, cmd, 0); err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -534,32 +526,3 @@ func genNewFleetService(newFile, oldFile, newVal, oldVal string) error {
}
return nil
}

// waitForActiveUnitsReplaceCmds() is a wrapper for waiting for N active units.
// The expected number of active units are given as a parameter "count".
// If cmd is "start", it expects that "count" active units are active.
// Otherwise, for "load" or "submit", it expects no active unit.
func waitForActiveUnitsReplaceCmds(cluster platform.Cluster, m platform.Member, cmd string, count int) error {
if cmd == "start" {
units, err := cluster.WaitForNActiveUnits(m, count)
if err != nil {
fmt.Errorf("%v", err)
}
_, found := units["hello.service"]
if len(units) != count || !found {
fmt.Errorf("Expected hello.service to be sole active unit, got %v", units)
}
} else {
// cmd is "load" or "submit", then there's no active unit
units, err := cluster.WaitForNActiveUnits(m, 0)
if err != nil {
fmt.Errorf("%v", err)
}
_, found := units["hello.service"]
if len(units) != 0 || !found {
fmt.Errorf("Expected hello.service to be sole active unit, got %v", units)
}
}

return nil
}

0 comments on commit cd3a786

Please sign in to comment.