<commit_before>package pool_test

import (
	"fmt"
	"testing"
	"time"

	"github.com/ardanlabs/kit/log"
	"github.com/ardanlabs/kit/pool"
	"github.com/ardanlabs/kit/tests"
)

func init() {
	tests.Init("KIT")
}

//==============================================================================

// theWork is the customer work type for using the pool.
type theWork struct {
	privateID int
}

// Work implements the DoWorker interface.
func (p *theWork) Work(context interface{}, id int) {
	log.Dev(context, "Work", "Performing Work with privateID %d\n", p.privateID)
}

// ExampleNewDoPool provides a basic example for using a DoPool.
func ExampleNewDoPool() {
	tests.ResetLog()
	defer tests.DisplayLog()

	// Create a configuration.
	cfg := pool.Config{
		MinRoutines: func() int { return 3 },
		MaxRoutines: func() int { return 4 },
	}

	// Create a new pool.
	p, err := pool.New("TEST", "TheWork", cfg)
	if err != nil {
		fmt.Println(err)
		return
	}

	// Pass in some work to be performed.
	p.Do("TEST", &theWork{})
	p.Do("TEST", &theWork{})
	p.Do("TEST", &theWork{})

	// Wait to the work to be processed.
	time.Sleep(100 * time.Millisecond)

	// Shutdown the pool.
	p.Shutdown("TEST")
}

// ExampleMetrics provides an example of the metrics handler being called.
func ExampleMetrics() {
	tests.ResetLog()
	defer tests.DisplayLog()

	// Create a configuration.
	cfg := pool.Config{
		MinRoutines: func() int { return 3 },
		MaxRoutines: func() int { return 4 },
	}

	// Create a new pool.
	p, err := pool.New("TEST", "TheWork", cfg)
	if err != nil {
		fmt.Println(err)
		return
	}

	// Pass in one piece of work to be performed.
	p.Do("TEST", &theWork{})

	// For the example, wait for it to display
	time.Sleep(time.Second)

	// Shutdown the pool.
	p.Shutdown("TEST")
}

// TestPool tests the pool is functional.
func TestPool(t *testing.T) {
	tests.ResetLog()
	defer tests.DisplayLog()

	t.Log("Given the need to validate the work pool functions.")
	{
		cfg := pool.Config{
			MinRoutines: func() int { return 100 },
			MaxRoutines: func() int { return 5000 },
		}
<commit_msg>Removed unnecessary example and fixed test<commit_after>package pool_test

import (
	"fmt"
	"testing"
	"time"

	"github.com/ardanlabs/kit/log"
	"github.com/ardanlabs/kit/pool"
	"github.com/ardanlabs/kit/tests"
)

func init() {
	tests.Init("KIT")
}

//==============================================================================

// theWork is the customer work type for using the pool.
type theWork struct {
	privateID int
}

// Work implements the DoWorker interface.
func (p *theWork) Work(context interface{}, id int) {
	log.Dev(context, "Work", "Performing Work with privateID %d\n", p.privateID)
}

// ExampleNew provides a basic example for using a pool.
func ExampleNew() {
	tests.ResetLog()
	defer tests.DisplayLog()

	// Create a configuration.
	cfg := pool.Config{
		MinRoutines: func() int { return 3 },
		MaxRoutines: func() int { return 4 },
	}

	// Create a new pool.
	p, err := pool.New("TEST", "TheWork", cfg)
	if err != nil {
		fmt.Println(err)
		return
	}

	// Pass in some work to be performed.
	p.Do("TEST", &theWork{})
	p.Do("TEST", &theWork{})
	p.Do("TEST", &theWork{})

	// Wait to the work to be processed.
	time.Sleep(100 * time.Millisecond)

	// Shutdown the pool.
	p.Shutdown("TEST")
}

// TestPool tests the pool is functional.
func TestPool(t *testing.T) {
	tests.ResetLog()
	defer tests.DisplayLog()

	t.Log("Given the need to validate the work pool functions.")
	{
		cfg := pool.Config{
			MinRoutines: func() int { return 100 },
			MaxRoutines: func() int { return 5000 },
		}

{'fraction_non_alphanumeric': 0.18328690807799444, 'fraction_numerical': 0.0072423398328690805, 'mean_word_length': 3.657587548638132, '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': '2924111', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1205, 'n_words': 371}