Skip to content

Commit 85f7f5c

Browse files
clear unused test code (#2026)
Remove testing tools which are no longer used & fix bug in catchup unit test.
1 parent f1e03f5 commit 85f7f5c

File tree

2 files changed

+4
-130
lines changed

2 files changed

+4
-130
lines changed

catchup/fetcher_test.go

Lines changed: 0 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@ package catchup
1818

1919
import (
2020
"context"
21-
"errors"
2221
"net"
2322
"net/http"
24-
"net/rpc"
2523
"net/url"
2624
"strings"
2725
"testing"
28-
"time"
2926

3027
"github.com/gorilla/mux"
3128
"github.com/stretchr/testify/require"
@@ -41,134 +38,8 @@ import (
4138
"github.com/algorand/go-algorand/logging"
4239
"github.com/algorand/go-algorand/network"
4340
"github.com/algorand/go-algorand/protocol"
44-
"github.com/algorand/go-algorand/rpcs"
45-
"github.com/algorand/go-algorand/util/bloom"
4641
)
4742

48-
type mockRunner struct {
49-
ran bool
50-
done chan *rpc.Call
51-
failWithNil bool
52-
failWithError bool
53-
txgroups [][]transactions.SignedTxn
54-
}
55-
56-
type mockRPCClient struct {
57-
client *mockRunner
58-
closed bool
59-
rootURL string
60-
log logging.Logger
61-
}
62-
63-
func (client *mockRPCClient) Close() error {
64-
client.closed = true
65-
return nil
66-
}
67-
68-
func (client *mockRPCClient) Address() string {
69-
return "mock.address."
70-
}
71-
func (client *mockRPCClient) Sync(ctx context.Context, bloom *bloom.Filter) (txgroups [][]transactions.SignedTxn, err error) {
72-
client.log.Info("MockRPCClient.Sync")
73-
select {
74-
case <-ctx.Done():
75-
return nil, errors.New("cancelled")
76-
default:
77-
}
78-
if client.client.failWithNil {
79-
return nil, errors.New("old failWithNil")
80-
}
81-
if client.client.failWithError {
82-
return nil, errors.New("failing call")
83-
}
84-
return client.client.txgroups, nil
85-
}
86-
func (client *mockRPCClient) getBlockBytes(ctx context.Context, r basics.Round) (data []byte, err error) {
87-
return nil, nil
88-
}
89-
90-
// network.HTTPPeer interface
91-
func (client *mockRPCClient) GetAddress() string {
92-
return client.rootURL
93-
}
94-
func (client *mockRPCClient) GetHTTPClient() *http.Client {
95-
return nil
96-
}
97-
98-
type mockClientAggregator struct {
99-
mocks.MockNetwork
100-
peers []network.Peer
101-
}
102-
103-
func (mca *mockClientAggregator) GetPeers(options ...network.PeerOption) []network.Peer {
104-
return mca.peers
105-
}
106-
107-
const numberOfPeers = 10
108-
109-
func makeMockClientAggregator(t *testing.T, failWithNil bool, failWithError bool) *mockClientAggregator {
110-
clients := make([]network.Peer, 0)
111-
for i := 0; i < numberOfPeers; i++ {
112-
runner := mockRunner{failWithNil: failWithNil, failWithError: failWithError, done: make(chan *rpc.Call)}
113-
clients = append(clients, &mockRPCClient{client: &runner, log: logging.TestingLog(t)})
114-
}
115-
t.Logf("len(mca.clients) = %d", len(clients))
116-
return &mockClientAggregator{peers: clients}
117-
}
118-
119-
type dummyFetcher struct {
120-
failWithNil bool
121-
failWithError bool
122-
fetchTimeout time.Duration
123-
}
124-
125-
// FetcherClient interface
126-
func (df *dummyFetcher) getBlockBytes(ctx context.Context, r basics.Round) (data []byte, err error) {
127-
if df.failWithNil {
128-
return nil, nil
129-
}
130-
if df.failWithError {
131-
return nil, errors.New("failing call")
132-
}
133-
134-
timer := time.NewTimer(df.fetchTimeout)
135-
defer timer.Stop()
136-
137-
// Fill in the dummy response with the correct round
138-
dummyBlock := rpcs.EncodedBlockCert{
139-
Block: bookkeeping.Block{
140-
BlockHeader: bookkeeping.BlockHeader{
141-
Round: r,
142-
},
143-
},
144-
Certificate: agreement.Certificate{
145-
Round: r,
146-
},
147-
}
148-
149-
encodedData := protocol.Encode(&dummyBlock)
150-
151-
select {
152-
case <-timer.C:
153-
case <-ctx.Done():
154-
return nil, ctx.Err()
155-
}
156-
157-
return encodedData, nil
158-
}
159-
160-
// FetcherClient interface
161-
func (df *dummyFetcher) Address() string {
162-
//logging.Base().Debug("dummyFetcher Address")
163-
return "dummyFetcher address"
164-
}
165-
166-
// FetcherClient interface
167-
func (df *dummyFetcher) Close() error {
168-
//logging.Base().Debug("dummyFetcher Close")
169-
return nil
170-
}
171-
17243
func buildTestLedger(t *testing.T, blk bookkeeping.Block) (ledger *data.Ledger, next basics.Round, b bookkeeping.Block, err error) {
17344
var user basics.Address
17445
user[0] = 123

catchup/service_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ func TestServiceFetchBlocksOneBlock(t *testing.T) {
262262
require.Equal(t, *block, localBlock)
263263
}
264264

265+
// TestAbruptWrites emulates the fact that the agreement can also generate new rounds
266+
// When caught up, and the agreement service is taking the lead, the sync() stops and
267+
// yields to the agreement. Agreement is emulated by the go func() loop in the test
265268
func TestAbruptWrites(t *testing.T) {
266269
numberOfBlocks := 100
267270

@@ -299,7 +302,6 @@ func TestAbruptWrites(t *testing.T) {
299302

300303
var wg sync.WaitGroup
301304
wg.Add(1)
302-
defer wg.Wait()
303305
go func() {
304306
defer wg.Done()
305307
for i := basics.Round(lastRound + 1); i <= basics.Round(numberOfBlocks); i++ {
@@ -317,6 +319,7 @@ func TestAbruptWrites(t *testing.T) {
317319
s.testStart()
318320

319321
s.sync()
322+
wg.Wait()
320323
require.Equal(t, remote.LastRound(), local.LastRound())
321324
}
322325

0 commit comments

Comments
 (0)