<commit_before>package sous

import (
	"testing"
	"time"

	"github.com/nyarly/testify/assert"
)

func dummyResolver() *Resolver {
	return NewResolver(NewDummyDeployer(), NewDummyRegistry(), &ResolveFilter{})
}

func setupAR() *AutoResolver {
	ls := SilentLogSet()
	return NewAutoResolver(dummyResolver(), &DummyStateManager{State: NewState()}, ls)
}

func TestDone(t *testing.T) {
	assert := assert.New(t)

	ar := setupAR()

	received := false
	var result error

	ar.addListener(func(tc, done TriggerChannel, ec announceChannel) {
		select {
		case err := <-ec:
			received = true
			result = err
			close(done)
		}
	})
	done := ar.Kickoff()
	for range done {
	}
	assert.True(received, "Should have received announcement")
}

func TestAutoResolver_CurrentStatus(t *testing.T) {
	assert := assert.New(t)
	ar := setupAR()

	tc := make(TriggerChannel, 10)
	ac := make(announceChannel, 1)
	done := make(TriggerChannel)
	tc.trigger()

	stable, live := ar.Statuses()
	assert.Nil(stable)
	assert.Nil(live)

	ar.resolveLoop(tc, done, ac)
	stable, live = ar.Statuses()
	assert.NotNil(stable)
	assert.NotNil(live)
}

func TestAfterDone(t *testing.T) {
	ar := setupAR()
	ar.UpdateTime = time.Duration(1)

	tc := make(TriggerChannel, 1)
	ac := make(announceChannel, 1)
	done := make(TriggerChannel, 1)

	ac <- nil
	ar.afterDone(tc, done, ac)
	select {
	case <-tc:
	case <-time.After(time.Duration(8 * time.Millisecond)):
		t.Error("Trigger channel took too long")
	default:
		t.Error("Trigger channel not triggered")
	}
}

func TestResolveLoop(t *testing.T) {
	ar := setupAR()
	//ar.LogSet.Debug.SetOutput(os.Stderr)

	tc := make(TriggerChannel, 10)
	ac := make(announceChannel, 1)
	done := make(TriggerChannel)

	for i := 0; i < 10; i++ {
		tc.trigger()
	}
	ar.resolveLoop(tc, done, ac)

	select {
	case <-tc:
		t.Error("Should have consumed all the triggers")
	default:
	}

	select {
	case <-ac:
	default:
		t.Error("Should have announced a result")
	}
}
<commit_msg>lib: Remove unused variable.<commit_after>package sous

import (
	"testing"
	"time"

	"github.com/nyarly/testify/assert"
)

func dummyResolver() *Resolver {
	return NewResolver(NewDummyDeployer(), NewDummyRegistry(), &ResolveFilter{})
}

func setupAR() *AutoResolver {
	ls := SilentLogSet()
	return NewAutoResolver(dummyResolver(), &DummyStateManager{State: NewState()}, ls)
}

func TestDone(t *testing.T) {
	assert := assert.New(t)

	ar := setupAR()

	received := false

	ar.addListener(func(tc, done TriggerChannel, ec announceChannel) {
		select {
		case <-ec:
			received = true
			close(done)
		}
	})
	done := ar.Kickoff()
	for range done {
	}
	assert.True(received, "Should have received announcement")
}

func TestAutoResolver_CurrentStatus(t *testing.T) {
	assert := assert.New(t)
	ar := setupAR()

	tc := make(TriggerChannel, 10)
	ac := make(announceChannel, 1)
	done := make(TriggerChannel)
	tc.trigger()

	stable, live := ar.Statuses()
	assert.Nil(stable)
	assert.Nil(live)

	ar.resolveLoop(tc, done, ac)
	stable, live = ar.Statuses()
	assert.NotNil(stable)
	assert.NotNil(live)
}

func TestAfterDone(t *testing.T) {
	ar := setupAR()
	ar.UpdateTime = time.Duration(1)

	tc := make(TriggerChannel, 1)
	ac := make(announceChannel, 1)
	done := make(TriggerChannel, 1)

	ac <- nil
	ar.afterDone(tc, done, ac)
	select {
	case <-tc:
	case <-time.After(time.Duration(8 * time.Millisecond)):
		t.Error("Trigger channel took too long")
	default:
		t.Error("Trigger channel not triggered")
	}
}

func TestResolveLoop(t *testing.T) {
	ar := setupAR()
	//ar.LogSet.Debug.SetOutput(os.Stderr)

	tc := make(TriggerChannel, 10)
	ac := make(announceChannel, 1)
	done := make(TriggerChannel)

	for i := 0; i < 10; i++ {
		tc.trigger()
	}
	ar.resolveLoop(tc, done, ac)

	select {
	case <-tc:
		t.Error("Should have consumed all the triggers")
	default:
	}

	select {
	case <-ac:
	default:
		t.Error("Should have announced a result")
	}
}

{'fraction_non_alphanumeric': 0.15252057613168724, 'fraction_numerical': 0.00720164609053498, 'mean_word_length': 4.291156462585034, 'pattern_counts': {'":': 0, '<': 17, '<?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': '3275883', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1412, 'n_words': 333}