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

Commit

Permalink
functional: make TestUnitSubmit() use a helper util.WaitForState
Browse files Browse the repository at this point in the history
TestUnitSubmit() now makes use of a new helper runListUnits() that
depends on util.WaitForState(), instead of running list-units every
time. This change will also help the whole functional test become
less racy.
  • Loading branch information
Dongsu Park committed Apr 11, 2016
1 parent 9f347fe commit 960ac0f
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions functional/unit_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ func TestUnitRunnable(t *testing.T) {
}
}

// TestUnitSubmit checks if a unit becomes submitted and destroyed successfully.
// First it submits a unit, and destroys the unit, verifies it's destroyed,
// finally submits the unit again.
func TestUnitSubmit(t *testing.T) {
cluster, err := platform.NewNspawnCluster("smoke")
if err != nil {
Expand All @@ -73,48 +76,47 @@ func TestUnitSubmit(t *testing.T) {
t.Fatal(err)
}

unitFile := "fixtures/units/hello.service"

// submit a unit and assert it shows up
if _, _, err := cluster.Fleetctl(m, "submit", "fixtures/units/hello.service"); err != nil {
_, _, err = cluster.Fleetctl(m, "submit", unitFile)
if err != nil {
t.Fatalf("Unable to submit fleet unit: %v", err)
}
stdout, _, err := cluster.Fleetctl(m, "list-units", "--no-legend")

// wait until the unit gets submitted up to 15 seconds
err = runListUnits(cluster, m, 1)
if err != nil {
t.Fatalf("Failed to run list-units: %v", err)
}
units := strings.Split(strings.TrimSpace(stdout), "\n")
if len(units) != 1 {
t.Fatalf("Did not find 1 unit in cluster: \n%s", stdout)
}

// submitting the same unit should not fail
if _, _, err = cluster.Fleetctl(m, "submit", "fixtures/units/hello.service"); err != nil {
_, _, err = cluster.Fleetctl(m, "submit", unitFile)
if err != nil {
t.Fatalf("Expected no failure when double-submitting unit, got this: %v", err)
}

// destroy the unit and ensure it disappears from the unit list
if _, _, err := cluster.Fleetctl(m, "destroy", "fixtures/units/hello.service"); err != nil {
_, _, err = cluster.Fleetctl(m, "destroy", unitFile)
if err != nil {
t.Fatalf("Failed to destroy unit: %v", err)
}
stdout, _, err = cluster.Fleetctl(m, "list-units", "--no-legend")
// wait until the unit gets submitted up to 15 seconds
err = runListUnits(cluster, m, 0)
if err != nil {
t.Fatalf("Failed to run list-units: %v", err)
}
if strings.TrimSpace(stdout) != "" {
t.Fatalf("Did not find 0 units in cluster: \n%s", stdout)
}

// submitting the unit after destruction should succeed
if _, _, err := cluster.Fleetctl(m, "submit", "fixtures/units/hello.service"); err != nil {
_, _, err = cluster.Fleetctl(m, "submit", unitFile)
if err != nil {
t.Fatalf("Unable to submit fleet unit: %v", err)
}
stdout, _, err = cluster.Fleetctl(m, "list-units", "--no-legend")
// wait until the unit gets submitted up to 15 seconds
err = runListUnits(cluster, m, 1)
if err != nil {
t.Fatalf("Failed to run list-units: %v", err)
}
units = strings.Split(strings.TrimSpace(stdout), "\n")
if len(units) != 1 {
t.Fatalf("Did not find 1 unit in cluster: \n%s", stdout)
}
}

func TestUnitRestart(t *testing.T) {
Expand Down

0 comments on commit 960ac0f

Please sign in to comment.