From 79aa4ebcfabe5e3e1b6c04de0bc5304e983ac03a Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Wed, 14 Dec 2016 17:55:42 +0100 Subject: [PATCH] Extend makeRPC test License: MIT Signed-off-by: Hector Sanjuan --- ipfs_cluster_test.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ipfs_cluster_test.go b/ipfs_cluster_test.go index 9bf6f9f9..885e5976 100644 --- a/ipfs_cluster_test.go +++ b/ipfs_cluster_test.go @@ -47,7 +47,7 @@ func TestMakeRPC(t *testing.T) { t.Error("expected empty response") } - // Test full channel and cancel + // Test full channel and cancel on send go func() { resp := MakeRPC(ctx, testCh, testReq, true) if resp.Error == nil || !strings.Contains(resp.Error.Error(), "timed out") { @@ -55,8 +55,21 @@ func TestMakeRPC(t *testing.T) { } }() // Previous request still taking the channel - time.Sleep(2 * time.Second) + time.Sleep(1 * time.Second) cancel() + + // Test cancelled while waiting for response context + ctx, cancel = context.WithCancel(context.Background()) + testCh = make(chan ClusterRPC, 1) + go func() { + resp := MakeRPC(ctx, testCh, testReq, true) + if resp.Error == nil || !strings.Contains(resp.Error.Error(), "timed out") { + t.Fatal("the operation should have been waiting and then cancelled") + } + }() + time.Sleep(1 * time.Second) + cancel() + time.Sleep(1 * time.Second) } func simulateAnswer(ch <-chan ClusterRPC, answer interface{}, err error) {