<commit_before>package functional

import (
	"strings"
	"testing"

	"github.com/coreos/fleet/functional/platform"
)
<commit_msg>test(functional): Add unit restart test<commit_after>package functional

import (
	"strings"
	"testing"

	"github.com/coreos/fleet/functional/platform"
)

func TestUnitRestart(t *testing.T) {
	cluster, err := platform.NewNspawnCluster("smoke")
	if err != nil {
		t.Fatal(err)
	}
	defer cluster.DestroyAll()

	if err := cluster.CreateMultiple(1, platform.MachineConfig{}); err != nil {
		t.Fatal(err)
	}
	_, err = waitForNMachines(1)
	if err != nil {
		t.Fatal(err)
	}

	if _, _, err := fleetctl("start", "fixtures/units/hello.service"); err != nil {
		t.Fatalf("Unable to start fleet unit: %v", err)
	}

	units, err := waitForNActiveUnits(1)
	if err != nil {
		t.Fatal(err)
	}
	_, found := units["hello.service"]
	if len(units) != 1 || !found {
		t.Fatalf("Expected hello.service to be sole active unit, got %v", units)
	}

	if _, _, err := fleetctl("stop", "hello.service"); err != nil {
		t.Fatal(err)
	}
	units, err = waitForNActiveUnits(0)
	if err != nil {
		t.Fatal(err)
	}
	if len(units) != 0 {
		t.Fatal("Zero units should be running, found %v", units)
	}

	if _, _, err := fleetctl("start", "hello.service"); err != nil {
		t.Fatalf("Unable to start fleet unit: %v", err)
	}
	units, err = waitForNActiveUnits(1)
	if err != nil {
		t.Fatal(err)
	}
	_, found = units["hello.service"]
	if len(units) != 1 || !found {
		t.Fatalf("Expected hello.service to be sole active unit, got %v", units)
	}

}

{'fraction_non_alphanumeric': 0.16851730894839975, 'fraction_numerical': 0.005225342913128674, 'mean_word_length': 3.91025641025641, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7532805', 'n_tokens_mistral': 605, 'n_tokens_neox': 570, 'n_words': 138}