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

rpctest: Make tests work properly with latest code. #2614

Merged
merged 1 commit into from
Mar 13, 2021
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ require (
github.com/jrick/logrotate v1.0.0
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68
)

Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/
golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc h1:zK/HqS5bZxDptfPJNq8v7vJfXtkU7r9TLIoSr1bXaP4=
golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
44 changes: 17 additions & 27 deletions rpctest/rpc_harness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ package rpctest

import (
"context"
"fmt"
"os"
"testing"
"time"
Expand All @@ -21,8 +20,6 @@ import (
dcrdtypes "github.com/decred/dcrd/rpc/jsonrpc/types/v3"
"github.com/decred/dcrd/txscript/v4"
"github.com/decred/dcrd/wire"

"golang.org/x/sync/errgroup"
)

const (
Expand Down Expand Up @@ -79,6 +76,10 @@ func testSendOutputs(ctx context.Context, r *Harness, t *testing.T) {

// Generate a single block, the transaction the wallet created should
// be found in this block.
if err := r.Node.RegenTemplate(ctx); err != nil {
t.Fatalf("unable to regenerate block template: %v", err)
}
time.Sleep(time.Millisecond * 500)
blockHashes, err := r.Node.Generate(ctx, 1)
if err != nil {
t.Fatalf("unable to generate single block: %v", err)
Expand All @@ -88,6 +89,10 @@ func testSendOutputs(ctx context.Context, r *Harness, t *testing.T) {
// Next, generate a spend much greater than the block reward. This
// transaction should also have been mined properly.
txid = genSpend(dcrutil.Amount(5000 * dcrutil.AtomsPerCoin))
if err := r.Node.RegenTemplate(ctx); err != nil {
t.Fatalf("unable to regenerate block template: %v", err)
}
time.Sleep(time.Millisecond * 500)
blockHashes, err = r.Node.Generate(ctx, 1)
if err != nil {
t.Fatalf("unable to generate single block: %v", err)
Expand Down Expand Up @@ -404,24 +409,19 @@ func testJoinMempools(ctx context.Context, r *Harness, t *testing.T) {
// Wait until the transaction shows up to ensure the two mempools are
// not the same.
harnessSynced := make(chan struct{})
var eg errgroup.Group
eg.Go(func() error {
go func() {
for {
poolHashes, err := r.Node.GetRawMempool(ctx, dcrdtypes.GRMAll)
if err != nil {
return fmt.Errorf("failed to retrieve harness mempool: %v", err)
t.Fatalf("failed to retrieve harness mempool: %v", err)
}
if len(poolHashes) > 0 {
break
}
time.Sleep(time.Millisecond * 100)
}
harnessSynced <- struct{}{}
return nil
})
if err := eg.Wait(); err != nil {
t.Fatal(err)
}
}()

select {
case <-harnessSynced:
Expand All @@ -432,16 +432,12 @@ func testJoinMempools(ctx context.Context, r *Harness, t *testing.T) {
// This select case should fall through to the default as the goroutine
// should be blocked on the JoinNodes call.
poolsSynced := make(chan struct{})
eg.Go(func() error {
go func() {
if err := JoinNodes(nodeSlice, Mempools); err != nil {
return fmt.Errorf("unable to join node on mempools: %v", err)
t.Fatalf("unable to join node on mempools: %v", err)
}
poolsSynced <- struct{}{}
return nil
})
if err := eg.Wait(); err != nil {
t.Fatal(err)
}
}()
select {
case <-poolsSynced:
t.Fatalf("mempools detected as synced yet harness has a new tx")
Expand Down Expand Up @@ -492,17 +488,12 @@ func testJoinBlocks(_ context.Context, r *Harness, t *testing.T) {

nodeSlice := []*Harness{r, harness}
blocksSynced := make(chan struct{})
var eg errgroup.Group
eg.Go(func() error {
go func() {
if err := JoinNodes(nodeSlice, Blocks); err != nil {
return fmt.Errorf("unable to join node on blocks: %v", err)
t.Fatalf("unable to join node on blocks: %v", err)
}
blocksSynced <- struct{}{}
return nil
})
if err := eg.Wait(); err != nil {
t.Fatal(err)
}
}()

// This select case should fall through to the default as the goroutine
// should be blocked on the JoinNodes calls.
Expand All @@ -524,7 +515,6 @@ func testJoinBlocks(_ context.Context, r *Harness, t *testing.T) {
// test hanging indefinitely, a 1 minute timeout is in place.
select {
case <-blocksSynced:
// fall through
case <-time.After(time.Minute):
t.Fatalf("blocks never detected as synced")
}
Expand Down