From 621e49bb465f500cc46d47e39e828cf76d6381d7 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 24 Jul 2018 14:35:44 +0200 Subject: update vendor --- .../mock/sample/concurrent/concurrent_test.go | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 vendor/github.com/golang/mock/sample/concurrent/concurrent_test.go (limited to 'vendor/github.com/golang/mock/sample/concurrent/concurrent_test.go') diff --git a/vendor/github.com/golang/mock/sample/concurrent/concurrent_test.go b/vendor/github.com/golang/mock/sample/concurrent/concurrent_test.go new file mode 100644 index 0000000..e4b271e --- /dev/null +++ b/vendor/github.com/golang/mock/sample/concurrent/concurrent_test.go @@ -0,0 +1,46 @@ +package concurrent + +import ( + "testing" + + "github.com/golang/mock/gomock" + "golang.org/x/net/context" + + mock "github.com/golang/mock/sample/concurrent/mock" +) + +func call(ctx context.Context, m Math) (int, error) { + result := make(chan int) + go func() { + result <- m.Sum(1, 2) + close(result) + }() + select { + case r := <-result: + return r, nil + case <-ctx.Done(): + return 0, ctx.Err() + } +} + +// testConcurrentFails is expected to fail (and is disabled). It +// demonstrates how to use gomock.WithContext to interrupt the test +// from a different goroutine. +func testConcurrentFails(t *testing.T) { + ctrl, ctx := gomock.WithContext(context.Background(), t) + defer ctrl.Finish() + m := mock.NewMockMath(ctrl) + if _, err := call(ctx, m); err != nil { + t.Error("call failed:", err) + } +} + +func TestConcurrentWorks(t *testing.T) { + ctrl, ctx := gomock.WithContext(context.Background(), t) + defer ctrl.Finish() + m := mock.NewMockMath(ctrl) + m.EXPECT().Sum(1, 2).Return(3) + if _, err := call(ctx, m); err != nil { + t.Error("call failed:", err) + } +} -- cgit v1.2.3