You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: retry_test.go
    path of file: ./repos/lo
    
    the code of the file until where you have to start completion: package lo

import (
	"fmt"
	"sync"
	"testing"
	"time"

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

func TestAttempt(t *testing.T) {
	t.Parallel()
	is := assert.New(t)

	err := fmt.Errorf("failed")

	iter1, err1 := Attempt(42, func(i int) error {
		return nil
	})
	iter2, err2 := Attempt(42, func(i int) error {
		if i == 5 {
			return nil
		}

		return err
	})
	iter3, err3 := Attempt(2, func(i int) error {
		if i == 5 {
			return nil
		}

		return err
	})
	iter4, err4 := Attempt(0, func(i int) error {
		if i < 42 {
			return err
		}

		return nil
	})

	is.Equal(iter1, 1)
	is.Equal(err1, nil)
	is.Equal(iter2, 6)
	is.Equal(err2, nil)
	is.Equal(iter3, 2)
	is.Equal(err3, err)
	is.Equal(iter4, 43)
	is.Equal(err4, nil)
}

func TestAttemptWithDelay(t *testing.T) {
	t.Parallel()
	is := assert.New(t)

	err := fmt.Errorf("failed")

	iter1, dur1, err1 := AttemptWithDelay(42, 10*time.Millisecond, func(i int, d time.Duration) error {
		return nil
	})
	iter2, dur2, err2 := AttemptWithDelay(42, 10*time.Millisecond, func(i int, d time.Duration
    
func TestDebounceBy(t *testing.T) {
	t.Parallel()
	is := assert.New(t)

	mu := sync.Mutex{}
	output := map[int]int{0: 0, 1: 0, 2: 0}

	f1 := func(key int, count int) {
		mu.Lock()
		output[key] += count
		mu.Unlock()
		// fmt.Printf("[key=%d] 1. Called once after 10ms when func stopped invoking!\n", key)
	}
	f2 := func(key int, count int) {
		mu.Lock()
		output[key] += count
		mu.Unlock()
		// fmt.Printf("[key=%d] 2. Called once after 10ms when func stopped invoking!\n", key)
	}
	f3 := func(key int, count int) {
		mu.Lock()
		output[key] += count
		mu.Unlock()
		// fmt.Printf("[key=%d] 3. Called once after 10ms when func stopped invoking!\n", key)
	}

	d1, _ := NewDebounceBy(10*time.Millisecond, f1)

	// execute 3 times
	for i := 0; i < 3; i++ {
		for j := 0; j < 10; j++ {
			for k := 0; k < 3; k++ {
				d1(k)
			}
		}
		time.Sleep(20 * time.Millisecond)
	}

	mu.Lock()
	is.EqualValues(output[0], 30)
	is.EqualValues(output[1], 30)
	is.EqualValues(output[2], 30)
	mu.Unlock()

	d2, _ := NewDebounceBy(10*time.Millisecond, f2)

	// execute once because it is always invoked and only last invoke is worked after 100ms
	for i := 0; i < 3; i++ {
		for j := 0; j < 5; j++ {
			for k := 0; k < 3; k++ {
				d2(k)
			}
		}
		time.Sleep(5 * time.Millisecond)
	}

	time.Sleep(10 * time.Millisecond)

	mu.Lock()
	is.EqualValues(output[0], 45)
	is.EqualValues(output[1], 45)
	is.EqualValues(output[2], 45)
	mu.Unlock()

	// execute once because it is canceled after 200ms.
	d3, cancel := NewDebounceBy(10*time.Millisecond, f3)
	for i := 0; i < 3; i++ {
		for j := 0; j < 10; j++ {
			for k := 0; k < 3; k++ {
				d3(k)
			}
		}

		time.Sleep(20 * time.Millisecond)
		if i == 0 {
			for k := 0; k < 3; k++ {
				cancel(k)
			}
		}
	}

	mu.Lock()
	is.EqualValues(output[0], 75)
	is.EqualValues(output[1], 75)
	is.EqualValues(output[2], 75)
	mu.Unlock()
}