Browse Source

rpc: fix tests to count mempool; copy responses to avoid data races

pull/43/merge
Ethan Buchman 9 years ago
parent
commit
d30fc2fa43
4 changed files with 19 additions and 11 deletions
  1. +2
    -1
      rpc/http_handlers.go
  2. +4
    -3
      rpc/test/http_rpc_test.go
  3. +4
    -3
      rpc/test/json_rpc_test.go
  4. +9
    -4
      rpc/test/test.go

+ 2
- 1
rpc/http_handlers.go View File

@ -181,7 +181,8 @@ func returnsToResponse(funcInfo *FuncWrapper, returns []reflect.Value) (interfac
}
}
v := funcInfo.response.Elem()
// copy the response struct (New returns a pointer so we have to Elem() twice)
v := reflect.New(funcInfo.response.Elem().Type()).Elem()
nFields := v.NumField()
for i := 0; i < nFields; i++ {
field := v.FieldByIndex([]int{i})


+ 4
- 3
rpc/test/http_rpc_test.go View File

@ -134,10 +134,11 @@ func TestHTTPBroadcastTx(t *testing.T) {
}
pool := node.MempoolReactor().Mempool
txs := pool.GetProposalTxs()
if len(txs) != 1 {
t.Fatal("The mem pool has %d txs. Expected 1", len(txs))
if len(txs) != mempoolCount+1 {
t.Fatalf("The mem pool has %d txs. Expected %d", len(txs), mempoolCount+1)
}
tx2 := txs[0].(*types.SendTx)
tx2 := txs[mempoolCount].(*types.SendTx)
mempoolCount += 1
if bytes.Compare(merkle.HashFromBinary(tx), merkle.HashFromBinary(tx2)) != 0 {
t.Fatal("inconsistent hashes for mempool tx and sent tx")
}


+ 4
- 3
rpc/test/json_rpc_test.go View File

@ -155,10 +155,11 @@ func TestJSONBroadcastTx(t *testing.T) {
}
pool := node.MempoolReactor().Mempool
txs := pool.GetProposalTxs()
if len(txs) != 1 {
t.Fatal("The mem pool has %d txs. Expected 1", len(txs))
if len(txs) != mempoolCount+1 {
t.Fatalf("The mem pool has %d txs. Expected %d", len(txs), mempoolCount+1)
}
tx2 := txs[0].(*types.SendTx)
tx2 := txs[mempoolCount].(*types.SendTx)
mempoolCount += 1
if bytes.Compare(merkle.HashFromBinary(tx), merkle.HashFromBinary(tx2)) != 0 {
t.Fatal("inconsistent hashes for mempool tx and sent tx")
}


+ 9
- 4
rpc/test/test.go View File

@ -22,10 +22,15 @@ import (
var (
rpcAddr = "127.0.0.1:8089"
requestAddr = "http://" + rpcAddr + "/"
chainId string
node *daemon.Node
userAddr = "D7DFF9806078899C8DA3FE3633CC0BF3C6C2B1BB"
userPriv = "FDE3BD94CB327D19464027BA668194C5EFA46AE83E8419D7542CFF41F00C81972239C21C81EA7173A6C489145490C015E05D4B97448933B708A7EC5B7B4921E3"
chainId string
node *daemon.Node
mempoolCount = 0
userAddr = "D7DFF9806078899C8DA3FE3633CC0BF3C6C2B1BB"
userPriv = "FDE3BD94CB327D19464027BA668194C5EFA46AE83E8419D7542CFF41F00C81972239C21C81EA7173A6C489145490C015E05D4B97448933B708A7EC5B7B4921E3"
userPub = "2239C21C81EA7173A6C489145490C015E05D4B97448933B708A7EC5B7B4921E3"
)


Loading…
Cancel
Save