forked from coreos/fleet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
functional: change logic of destroying all units
So far the logic of destroyUnitRetrying() was sub-optimal, as it repeatedly tried to destroy every unit. To improve its logic for better efficiency, change its logic into waiting for every unit being removed only at the end of tests. Also convert the helper destroyUnitRetrying into a method of nspawnCluster, WaitForNAllUnits(), just like the existing method WaitForNActiveUnits().
- Loading branch information
Dongsu Park
committed
Mar 21, 2016
1 parent
6f6cf81
commit 8a22f07
Showing
3 changed files
with
42 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,31 @@ func (nc *nspawnCluster) FleetctlWithInput(m Member, input string, args ...strin | |
return util.RunFleetctlWithInput(input, args...) | ||
} | ||
|
||
func (nc *nspawnCluster) WaitForNAllUnits(m Member, count int) error { | ||
timeout := 15 * time.Second | ||
alarm := time.After(timeout) | ||
|
||
ticker := time.Tick(250 * time.Millisecond) | ||
loop: | ||
for { | ||
select { | ||
case <-alarm: | ||
return fmt.Errorf("failed to find %d units within %v", count, timeout) | ||
case <-ticker: | ||
stdout, _, err := nc.Fleetctl(m, "list-units", "--no-legend") | ||
if err != nil { | ||
continue | ||
} | ||
units := strings.Split(strings.TrimSpace(stdout), "\n") | ||
if (count == 0 && len(stdout) == 0) || len(units) == count { | ||
break loop | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
antrik
|
||
|
||
func (nc *nspawnCluster) WaitForNActiveUnits(m Member, count int) (map[string][]util.UnitState, error) { | ||
var nactive int | ||
states := make(map[string][]util.UnitState) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The naming is a bit weird... Maybe simply
WaitForNUnits
?