瀏覽代碼

add unit test for mapreduce

kevin 4 年之前
父節點
當前提交
1cb17311dd
共有 1 個文件被更改,包括 16 次插入0 次删除
  1. 16 0
      core/mr/mapreduce_test.go

+ 16 - 0
core/mr/mapreduce_test.go

@@ -378,6 +378,22 @@ func TestMapReduceVoidCancelWithRemains(t *testing.T) {
 	assert.True(t, done.True())
 	assert.True(t, done.True())
 }
 }
 
 
+func TestMapReduceWithoutReducerWrite(t *testing.T) {
+	uids := []int{1, 2, 3}
+	res, err := MapReduce(func(source chan<- interface{}) {
+		for _, uid := range uids {
+			source <- uid
+		}
+	}, func(item interface{}, writer Writer, cancel func(error)) {
+		writer.Write(item)
+	}, func(pipe <-chan interface{}, writer Writer, cancel func(error)) {
+		drain(pipe)
+		// not calling writer.Write(...), should not panic
+	})
+	assert.Equal(t, ErrReduceNoOutput, err)
+	assert.Nil(t, res)
+}
+
 func BenchmarkMapReduce(b *testing.B) {
 func BenchmarkMapReduce(b *testing.B) {
 	b.ReportAllocs()
 	b.ReportAllocs()