<commit_before>package endtoend_test

import (
	"testing"

	"github.com/kopia/kopia/snapshot"
	"github.com/kopia/kopia/tests/testenv"
)

func TestFullMaintenance(t *testing.T) {
	t.Parallel()

	e := testenv.NewCLITest(t)

	e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir)
	defer e.RunAndExpectSuccess(t, "repo", "disconnect")

	var snap snapshot.Manifest

	// after creation we'll have kopia.repository, 1 index + 1 pack blob
	if got, want := e.RunAndExpectSuccess(t, "blob", "list"), 3; len(got) != want {
		t.Fatalf("unexpected number of initial blobs: %v, want %v", got, want)
	}

	mustParseJSONLines(t, e.RunAndExpectSuccess(t, "snapshot", "create", sharedTestDataDir1, "--json"), &snap)
	e.RunAndExpectSuccess(t, "snapshot", "delete", string(snap.ID), "--delete")

	e.RunAndVerifyOutputLineCount(t, 0, "snapshot", "list")

	originalBlobCount := len(e.RunAndExpectSuccess(t, "blob", "list"))

	e.RunAndVerifyOutputLineCount(t, 0, "maintenance", "run", "--full")

	if got := len(e.RunAndExpectSuccess(t, "blob", "list")); got != originalBlobCount {
		t.Fatalf("full maintenance is not expected to change any blobs due to safety margins (got %v, was %v)", got, originalBlobCount)
	}

	// now rerun with --safety=none<commit_msg>testing: fixed TestFullMaintenance flake (#944)<commit_after>package endtoend_test

import (
	"testing"
	"time"

	"github.com/kopia/kopia/snapshot"
	"github.com/kopia/kopia/tests/testenv"
)

func TestFullMaintenance(t *testing.T) {
	t.Parallel()

	e := testenv.NewCLITest(t)

	e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir)
	defer e.RunAndExpectSuccess(t, "repo", "disconnect")

	var snap snapshot.Manifest

	// after creation we'll have kopia.repository, 1 index + 1 pack blob
	if got, want := e.RunAndExpectSuccess(t, "blob", "list"), 3; len(got) != want {
		t.Fatalf("unexpected number of initial blobs: %v, want %v", got, want)
	}

	mustParseJSONLines(t, e.RunAndExpectSuccess(t, "snapshot", "create", sharedTestDataDir1, "--json"), &snap)

	// avoid create and delete in the same second.
	time.Sleep(2 * time.Second)
	e.RunAndExpectSuccess(t, "snapshot", "delete", string(snap.ID), "--delete")

	e.RunAndVerifyOutputLineCount(t, 0, "snapshot", "list")

	originalBlobCount := len(e.RunAndExpectSuccess(t, "blob", "list"))

	e.RunAndVerifyOutputLineCount(t, 0, "maintenance", "run", "--full")

	if got := len(e.RunAndExpectSuccess(t, "blob", "list")); got != originalBlobCount {
		t.Fatalf("full maintenance is not expected to change any blobs due to safety margins (got %v, was %v)", got, originalBlobCount)
	}

	// now rerun with --safety=none
{'fraction_non_alphanumeric': 0.1645185746777862, 'fraction_numerical': 0.006065200909780136, 'mean_word_length': 5.151515151515151, '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': '7475213', 'n_tokens_mistral': 970, 'n_tokens_neox': 932, 'n_words': 232}