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

Commit

Permalink
functional: a new test TestScheduleReplace
Browse files Browse the repository at this point in the history
TestScheduleReplace starts 1 unit, followed by starting another unit
that replaces the 1st unit. Then it verifies that the 2 units are
started on different machines.
  • Loading branch information
Dongsu Park committed May 3, 2016
1 parent 12f2ab1 commit 0c52441
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
5 changes: 5 additions & 0 deletions functional/fixtures/units/replace.0.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[Unit]
Description=Test Unit

[Service]
ExecStart=/bin/bash -c "while true; do echo Hello, World!; sleep 1; done"
8 changes: 8 additions & 0 deletions functional/fixtures/units/replace.1.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Unit]
Description=Test Unit

[Service]
ExecStart=/bin/bash -c "while true; do echo Hello, World!; sleep 1; done"

[X-Fleet]
Replaces=replace.0.service
70 changes: 70 additions & 0 deletions functional/scheduling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package functional
import (
"fmt"
"os"
"path"
"path/filepath"
"strings"
"testing"
Expand Down Expand Up @@ -320,6 +321,75 @@ func TestScheduleOneWayConflict(t *testing.T) {

}

// TestScheduleReplace starts 1 unit, followed by starting another unit
// that replaces the 1st unit. Then it verifies that the 2 units are
// started on different machines.
func TestScheduleReplace(t *testing.T) {
cluster, err := platform.NewNspawnCluster("smoke")
if err != nil {
t.Fatal(err)
}
defer cluster.Destroy(t)

// Start with a simple three-node cluster
members, err := platform.CreateNClusterMembers(cluster, 2)
if err != nil {
t.Fatal(err)
}
m0 := members[0]
if _, err := cluster.WaitForNMachines(m0, 2); err != nil {
t.Fatal(err)
}

// Start a unit without Replaces
uName0 := "fixtures/units/replace.0.service"
if stdout, stderr, err := cluster.Fleetctl(m0, "start", "--no-block", uName0); err != nil {
t.Fatalf("Failed starting unit %s: \nstdout: %s\nstderr: %s\nerr: %v", uName0, stdout, stderr, err)
}

active, err := cluster.WaitForNActiveUnits(m0, 1)
if err != nil {
t.Fatal(err)
}
_, err = util.ActiveToSingleStates(active)
if err != nil {
t.Fatal(err)
}

// Start a unit that replaces the former one, replace.0.service
uName1 := "fixtures/units/replace.1.service"
if stdout, stderr, err := cluster.Fleetctl(m0, "start", "--no-block", uName1); err != nil {
t.Fatalf("Failed starting unit %s: \nstdout: %s\nstderr: %s\nerr: %v", uName1, stdout, stderr, err)
}

// Both units should show up
stdout, _, err := cluster.Fleetctl(m0, "list-unit-files", "--no-legend")
if err != nil {
t.Fatalf("Failed to run list-unit-files: %v", err)
}
units := strings.Split(strings.TrimSpace(stdout), "\n")
if len(units) != 2 {
t.Fatalf("Did not find two units in cluster: \n%s", stdout)
}
active, err = cluster.WaitForNActiveUnits(m0, 2)
if err != nil {
t.Fatal(err)
}
states, err := util.ActiveToSingleStates(active)
if err != nil {
t.Fatal(err)
}

// unit replace.1.service must be located on a different machine from 0
uNameBase0 := path.Base(uName0)
uNameBase1 := path.Base(uName1)
mach0 := states[uNameBase0].Machine
mach1 := states[uNameBase1].Machine
if mach0 == mach1 {
t.Fatalf("machine for %s is %s, the same as that of %s.", uNameBase0, mach0, uNameBase1)
}
}

// Ensure units can be scheduled directly to a given machine using the
// MachineID unit option.
func TestScheduleConditionMachineID(t *testing.T) {
Expand Down

0 comments on commit 0c52441

Please sign in to comment.