Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added tests for GetBestBlockHashAsync #2057

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions rpcclient/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"net/http/httptest"
"strings"
"sync"
"testing"
"time"
)
Expand Down Expand Up @@ -190,6 +191,48 @@ func TestClientConnectedToWSServerRunner(t *testing.T) {
}
},
},
TestTableItem{
Name: "TestGetBestBlockHashAsync",
TestCase: func(t *testing.T) {
client, serverReceivedChannel, cleanup := makeClient(t)
defer cleanup()
ch := client.GetBestBlockHashAsync()

message := <-serverReceivedChannel
if message != "{\"jsonrpc\":\"1.0\",\"method\":\"getbestblockhash\",\"params\":[],\"id\":1}" {
t.Fatalf("received unexpected message: %s", message)
}

expectedResponse := Response{}

wg := sync.WaitGroup{}

wg.Add(1)
go func() {
defer wg.Done()
for {
client.requestLock.Lock()
if client.requestList.Len() > 0 {
r := client.requestList.Back()
r.Value.(*jsonRequest).responseChan <- &expectedResponse
client.requestLock.Unlock()
return
}
client.requestLock.Unlock()
}
}()

response := <-ch

if &expectedResponse != response {
t.Fatalf("received unexepcted response")
}

// ensure the goroutine created in this test exists,
// the test is ran with a timeout
wg.Wait()
},
},
}

// since these tests rely on concurrency, ensure there is a resonable timeout
Expand Down
Loading