<commit_before>package coretest

import (
	"io"
	"os"
	"path"
	"strings"
	"syscall"
	"testing"
	"time"
)

const (
	fleetctlBinPath = "/usr/bin/fleetctl"
	tryTimes = 5
	tryInterval = 500 * time.Millisecond
	serviceData = `[Unit]
Description=Hello World
[Service]
ExecStart=/bin/bash -c "while true; do echo \"Hello, world\"; sleep 1; done"
`
)

// TestFleetctlListMachines tests that 'fleetctl list-machines' works
// and print itself out at least.
func TestFleetctlListMachines(t *testing.T) {
	stdout, stderr, err := Run(fleetctlBinPath, "list-machines", "--no-legend")
	if err != nil {
		t.Fatalf("fleetctl list-machines failed with error: %v\nstdout: %s\nstderr: %s", err, stdout, stderr)
	}

	stdout = strings.TrimSpace(stdout)
	if len(strings.Split(stdout, "\n")) == 0 {
		t.Fatalf("Failed listing out at least one machine\nstdout: %s", stdout)
	}
}

func checkServiceState(name string, t *testing.T) (exist bool, active bool) {
	stdout, stderr, err := Run(fleetctlBinPath, "list-units", "--no-legend")
	if err != nil {
		t.Fatalf("fleetctl list-units failed with error: %v\nstdout: %s\nstderr: %s", err, stdout, stderr)
	}

	lines := strings.Split(stdout, "\n")
	for _, line := range lines {
		if !strings.Contains(line, name) {
			continue
		}
		exist = true
		if strings.Contains(line, "active") {
			active = true
			return
		}<commit_msg>fix(fleet): Use "running" to identify an active service<commit_after>package coretest

import (
	"io"
	"os"
	"path"
	"strings"
	"syscall"
	"testing"
	"time"
)

const (
	fleetctlBinPath = "/usr/bin/fleetctl"
	tryTimes = 5
	tryInterval = 500 * time.Millisecond
	serviceData = `[Unit]
Description=Hello World
[Service]
ExecStart=/bin/bash -c "while true; do echo \"Hello, world\"; sleep 1; done"
`
)

// TestFleetctlListMachines tests that 'fleetctl list-machines' works
// and print itself out at least.
func TestFleetctlListMachines(t *testing.T) {
	stdout, stderr, err := Run(fleetctlBinPath, "list-machines", "--no-legend")
	if err != nil {
		t.Fatalf("fleetctl list-machines failed with error: %v\nstdout: %s\nstderr: %s", err, stdout, stderr)
	}

	stdout = strings.TrimSpace(stdout)
	if len(strings.Split(stdout, "\n")) == 0 {
		t.Fatalf("Failed listing out at least one machine\nstdout: %s", stdout)
	}
}

func checkServiceState(name string, t *testing.T) (exist bool, active bool) {
	stdout, stderr, err := Run(fleetctlBinPath, "list-units", "--no-legend")
	if err != nil {
		t.Fatalf("fleetctl list-units failed with error: %v\nstdout: %s\nstderr: %s", err, stdout, stderr)
	}

	lines := strings.Split(stdout, "\n")
	for _, line := range lines {
		if !strings.Contains(line, name) {
			continue
		}
		exist = true
		if strings.Contains(line, "running") {
			active = true
			return
		}
{'fraction_non_alphanumeric': 0.15224534501642936, 'fraction_numerical': 0.004381161007667032, 'mean_word_length': 4.131086142322097, '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': '4350160', 'n_tokens_mistral': 1081, 'n_tokens_neox': 1002, 'n_words': 271}