<commit_before>package queue_test

import (
	"context"
	"fmt"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	queue "github.com/DMarby/picsum-photos/queue"

	"testing"
)

func TestImage(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "queue")
}

var workerQueue *queue.Queue
var cancel context.CancelFunc

func setupQueue(f func(data interface{}) (interface{}, error)) (*queue.Queue, context.CancelFunc) {
	ctx, cancel := context.WithCancel(context.Background())
	workerQueue := queue.New(ctx, 5, f)
	go workerQueue.Run()
	return workerQueue, cancel
}

var _ = BeforeSuite(func() {
	workerQueue, cancel = setupQueue(func(data interface{}) (interface{}, error) {
		stringData, _ := data.(string)
		return stringData, nil
	})
})

var _ = Describe("Queue", func() {
	Describe("Process", func() {
		It("Processes a task without error", func() {
			data, err := workerQueue.Process("test")
			Ω(err).ShouldNot(HaveOccurred())
			Ω(data).Should(Equal("test"))
		})

		It("Processes a task with error", func() {
			errorQueue, errorCancel := setupQueue(func(data interface{}) (interface{}, error) {
				return nil, fmt.Errorf("custom error")
			})
			defer errorCancel()
			_, err := errorQueue.Process("test")
			Ω(err).Should(MatchError("custom error"))
		})

		It("Errors when queue is shut down", func() {
			cancel()
			_, err := workerQueue.Process("test")
			Ω(err).Should(MatchError("queue has been shutdown"))
		})
	})

})

var _ = AfterSuite(func() {
	cancel()
})<commit_msg>Create a new queue for every test<commit_after>package queue_test

import (
	"context"
	"fmt"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	queue "github.com/DMarby/picsum-photos/queue"

	"testing"
)

func TestImage(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "queue")
}

var workerQueue *queue.Queue
var cancel context.CancelFunc

func setupQueue(f func(data interface{}) (interface{}, error)) (*queue.Queue, context.CancelFunc) {
	ctx, cancel := context.WithCancel(context.Background())
	workerQueue := queue.New(ctx, 5, f)
	go workerQueue.Run()
	return workerQueue, cancel
}

var _ = BeforeEach(func() {
	workerQueue, cancel = setupQueue(func(data interface{}) (interface{}, error) {
		stringData, _ := data.(string)
		return stringData, nil
	})
})

var _ = Describe("Queue", func() {
	Describe("Process", func() {
		It("Processes a task without error", func() {
			data, err := workerQueue.Process("test")
			Ω(err).ShouldNot(HaveOccurred())
			Ω(data).Should(Equal("test"))
		})

		It("Processes a task with error", func() {
			errorQueue, errorCancel := setupQueue(func(data interface{}) (interface{}, error) {
				return nil, fmt.Errorf("custom error")
			})
			defer errorCancel()
			_, err := errorQueue.Process("test")
			Ω(err).Should(MatchError("custom error"))
		})

		It("Errors when queue is shut down", func() {
			cancel()
			_, err := workerQueue.Process("test")
			Ω(err).Should(MatchError("queue has been shutdown"))
		})
	})

})

var _ = AfterEach(func() {
	cancel()
})
{'fraction_non_alphanumeric': 0.16799468791500663, 'fraction_numerical': 0.0006640106241699867, 'mean_word_length': 4.589981447124305, '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': '3784350', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1010, 'n_words': 226}