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: producer_test.go
    path of file: ./repos/goka
    
    the code of the file until where you have to start completion: // +build goka

package goka

import (

    
func TestProducerError(t *testing.T) {
	cfg := DefaultConfig()
	p, err := NewProducer([]string{"localhost:9092"}, cfg)

	if err != nil {
		t.Fatalf("error creating producer: %v", err)
	}

	var (
		promises     []*Promise
		donePromises int64
		emitted      int64
		done         = make(chan bool)
	)

	go func() {
		defer func() {
			recover()
		}()
		defer close(done)
		for {
			promise := p.Emit("test", "test", []byte{})
			promise.Then(func(err error) {
				atomic.AddInt64(&donePromises, 1)
				if err != nil {
					log.Printf("error producing message: %v", err)
				}
			})
			promises = append(promises, promise)
			emitted++
			time.Sleep(20 * time.Millisecond)
		}
	}()

	// let it run for 1 second
	time.Sleep(1000 * time.Millisecond)

	// close the producer
	err = p.Close()
	if err != nil {
		log.Printf("Error closing producer: %v", err)
	}
	// wait for the promises to be
	<-done

	if len(promises) != int(emitted) {
		t.Errorf("Promises/Emits do not match: promises: %d, emitted. %d", len(promises), emitted)
	}
	if len(promises) != int(donePromises) {
		t.Errorf("Promises/Done promises do not match: promises: %d, done. %d", len(promises), donePromises)
	}
}