Exemple #1
0
func _testSendGroup(server *machinery.Server, t *testing.T) {
	tasks := _getTasks()

	group := machinery.NewGroup(&tasks[0], &tasks[1], &tasks[2])
	asyncResults, err := server.SendGroup(group)
	if err != nil {
		t.Error(err)
	}

	expectedResults := []int64{2, 4, 11}

	actualResults := make([]int64, 3)

	for i, asyncResult := range asyncResults {
		result, err := asyncResult.Get()
		if err != nil {
			t.Error(err)
		}
		intResult, ok := result.Interface().(int64)
		if !ok {
			t.Errorf("Could not convert %v to int64", result.Interface())
		}
		actualResults[i] = intResult
	}

	sort.Sort(ascendingInt64s(actualResults))

	if !reflect.DeepEqual(expectedResults, actualResults) {
		t.Errorf(
			"expected results = %v, actual results = %v",
			expectedResults,
			actualResults,
		)
	}
}
Exemple #2
0
func _testSendTask(server *machinery.Server, t *testing.T) {
	tasks := _getTasks()

	asyncResult, err := server.SendTask(&tasks[0])
	if err != nil {
		t.Error(err)
	}

	result, err := asyncResult.Get()
	if err != nil {
		t.Error(err)
	}

	if result.Interface() != int64(2) {
		t.Errorf(
			"result = %v(%v), want int64(2)",
			result.Type().String(),
			result.Interface(),
		)
	}
}
Exemple #3
0
func _testSendChain(server *machinery.Server, t *testing.T) {
	tasks := _getTasks()

	chain := machinery.NewChain(&tasks[1], &tasks[2], &tasks[3])
	chainAsyncResult, err := server.SendChain(chain)
	if err != nil {
		t.Error(err)
	}

	result, err := chainAsyncResult.Get()
	if err != nil {
		t.Error(err)
	}

	if result.Interface() != int64(60) {
		t.Errorf(
			"result = %v(%v), want int64(60)",
			result.Type().String(),
			result.Interface(),
		)
	}
}
Exemple #4
0
func _testSendChord(server *machinery.Server, t *testing.T) {
	tasks := _getTasks()

	group := machinery.NewGroup(&tasks[0], &tasks[1], &tasks[2])
	chord := machinery.NewChord(group, &tasks[4])
	chordAsyncResult, err := server.SendChord(chord)
	if err != nil {
		t.Error(err)
	}

	result, err := chordAsyncResult.Get()
	if err != nil {
		t.Error(err)
	}

	if result.Interface() != int64(88) {
		t.Errorf(
			"result = %v(%v), want int64(88)",
			result.Type().String(),
			result.Interface(),
		)
	}
}