package apikey

import (
	"fmt"
	"sync"
	"testing"
)

func Test(t *testing.T) {
	g := NewKeyGenerator()

	wg := sync.WaitGroup{}
	var lck sync.Mutex

	var count = 0
	keys := map[string]struct{}{}

	for i := 0; i < 500; i++ {
		wg.Add(1)
		go func() {
			bit := g.NextKey()
			fmt.Println(bit)

			lck.Lock()
			defer lck.Unlock()
			_, ok := keys[bit]
			if ok {
				count++
				fmt.Println("conflict:", bit)
			} else {
				keys[bit] = struct{}{}
			}
			wg.Done()
		}()
	}
	wg.Wait()
	fmt.Println(len(keys))
	fmt.Println(count)
}
