コード例 #1
0
ファイル: util_test.go プロジェクト: fortytw2/thermocline
// SetupBroker is a test utility function
func SetupBroker(t *testing.T) (thermocline.Broker, <-chan *thermocline.Task, chan<- *thermocline.Task) {
	var broker thermocline.Broker
	broker = mem.NewBroker()

	reader, err := broker.Read("test", thermocline.NoVersion)
	if err != nil {
		t.Errorf("could not open queue '%s'", err)
	}

	writer, err := broker.Write("test", thermocline.NoVersion)
	if err != nil {
		t.Errorf("could not open queue '%s'", err)
	}

	return broker, reader, writer
}
コード例 #2
0
ファイル: worker_test.go プロジェクト: fortytw2/thermocline
func TestWorkerRetries(t *testing.T) {
	t.Parallel()

	var broker thermocline.Broker
	broker = mem.NewBroker()

	reader, err := broker.Read("test", thermocline.NoVersion)
	if err != nil {
		t.Errorf("could not open queue '%s'", err)
	}

	writer, err := broker.Write("test", thermocline.NoVersion)
	if err != nil {
		t.Errorf("could not open queue '%s'", err)
	}

	tn := rand.Intn(256)
	for i := range iter.N(tn) {
		task, err := thermocline.NewTask(fmt.Sprintf("test %d", i))
		if err != nil {
			t.Error("could not create test task", err)
		}

		writer <- task
	}

	stopper := make(chan struct{})
	var worked int64
	wg := &sync.WaitGroup{}
	for range iter.N(rand.Intn(256)) {
		wg.Add(1)
		go thermocline.NewWorker(reader, writer, func(task *thermocline.Task) ([]*thermocline.Task, error) {
			atomic.AddInt64(&worked, 1)
			return nil, errors.New("cannot process task, herp derup")
		}, stopper).Work(wg)
	}

	time.Sleep(500 * time.Millisecond)
	close(stopper)

	wg.Wait()

	if atomic.LoadInt64(&worked) != int64(tn*3) {
		t.Errorf("%d tasks not worked in retry test after 500ms, actually %d", tn*3, atomic.LoadInt64(&worked))
	}
}
コード例 #3
0
ファイル: brokers_test.go プロジェクト: fortytw2/thermocline
package brokers_test

import (
	"testing"

	"github.com/fortytw2/thermocline"
	"github.com/fortytw2/thermocline/brokers/mem"
)

var brokers = []thermocline.Broker{mem.NewBroker()}

func TestBrokers(t *testing.T) {

}