From 1cb17311dddf2e964bd7e3adca967fedb043bbbf Mon Sep 17 00:00:00 2001 From: kevin Date: Sun, 6 Sep 2020 18:19:19 +0800 Subject: [PATCH] add unit test for mapreduce --- core/mr/mapreduce_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core/mr/mapreduce_test.go b/core/mr/mapreduce_test.go index 8cd6b1ab..9262b027 100644 --- a/core/mr/mapreduce_test.go +++ b/core/mr/mapreduce_test.go @@ -378,6 +378,22 @@ func TestMapReduceVoidCancelWithRemains(t *testing.T) { 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) { b.ReportAllocs()