From 0313fa82979d0194feab92ca4c3231e962ef6892 Mon Sep 17 00:00:00 2001 From: Dongsu Park Date: Mon, 11 Apr 2016 11:23:52 +0200 Subject: [PATCH] functional: a new test TestUnitLoad to check fleetctl {load,unload} A new test TestUnitLoad verifies that "fleetctl {load,unload}" correctly works: load -> list-units -> unload -> list-units -> load --- functional/unit_action_test.go | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/functional/unit_action_test.go b/functional/unit_action_test.go index dbca3bbb5..c64f66d9c 100644 --- a/functional/unit_action_test.go +++ b/functional/unit_action_test.go @@ -119,6 +119,64 @@ func TestUnitSubmit(t *testing.T) { } } +// TestUnitLoad checks if a unit becomes loaded and unloaded successfully. +// First it load a unit, and unloads the unit, verifies it's unloaded, +// finally loads the unit again. +func TestUnitLoad(t *testing.T) { + cluster, err := platform.NewNspawnCluster("smoke") + if err != nil { + t.Fatal(err) + } + defer cluster.Destroy() + + m, err := cluster.CreateMember() + if err != nil { + t.Fatal(err) + } + _, err = cluster.WaitForNMachines(m, 1) + if err != nil { + t.Fatal(err) + } + + unitFile := "fixtures/units/hello.service" + + // load a unit and assert it shows up + _, _, err = cluster.Fleetctl(m, "load", unitFile) + if err != nil { + t.Fatalf("Unable to load fleet unit: %v", err) + } + + // wait until the unit gets unloaded up to 15 seconds + err = runListUnits(cluster, m, 1) + if err != nil { + t.Fatalf("Failed to run list-units: %v", err) + } + + // unload the unit and ensure it disappears from the unit list + _, _, err = cluster.Fleetctl(m, "unload", unitFile) + if err != nil { + t.Fatalf("Failed to unload unit: %v", err) + } + + // wait until the unit gets unloaded up to 15 seconds + err = runListUnits(cluster, m, 0) + if err != nil { + t.Fatalf("Failed to run list-units: %v", err) + } + + // loading the unit after destruction should succeed + _, _, err = cluster.Fleetctl(m, "load", unitFile) + if err != nil { + t.Fatalf("Unable to load fleet unit: %v", err) + } + + // wait until the unit gets unloaded up to 15 seconds + err = runListUnits(cluster, m, 1) + if err != nil { + t.Fatalf("Failed to run list-units: %v", err) + } +} + func TestUnitRestart(t *testing.T) { cluster, err := platform.NewNspawnCluster("smoke") if err != nil {