mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
swarm/storage/localstore: adjust pull sync tests
This commit is contained in:
parent
1d2d470b7c
commit
c26c979ca7
1 changed files with 14 additions and 14 deletions
|
|
@ -44,7 +44,7 @@ func TestDB_SubscribePull(t *testing.T) {
|
||||||
|
|
||||||
// prepopulate database with some chunks
|
// prepopulate database with some chunks
|
||||||
// before the subscription
|
// before the subscription
|
||||||
uploadRandomChunksBin(t, db, addrs, uploader, &wantedChunksCount, 10)
|
uploadRandomChunksBin(t, db, uploader, addrs, &wantedChunksCount, 10)
|
||||||
|
|
||||||
// set a timeout on subscription
|
// set a timeout on subscription
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
|
@ -59,16 +59,16 @@ func TestDB_SubscribePull(t *testing.T) {
|
||||||
defer stop()
|
defer stop()
|
||||||
|
|
||||||
// receive and validate addresses from the subscription
|
// receive and validate addresses from the subscription
|
||||||
go checkBin(ctx, bin, ch, addrs, errChan)
|
go readPullSubscriptionBin(ctx, bin, ch, addrs, errChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
// upload some chunks just after subscribe
|
// upload some chunks just after subscribe
|
||||||
uploadRandomChunksBin(t, db, addrs, uploader, &wantedChunksCount, 5)
|
uploadRandomChunksBin(t, db, uploader, addrs, &wantedChunksCount, 5)
|
||||||
|
|
||||||
time.Sleep(500 * time.Millisecond)
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
|
||||||
// upload some chunks after some short time
|
// upload some chunks after some short time
|
||||||
uploadRandomChunksBin(t, db, addrs, uploader, &wantedChunksCount, 3)
|
uploadRandomChunksBin(t, db, uploader, addrs, &wantedChunksCount, 3)
|
||||||
|
|
||||||
checkErrChan(ctx, t, errChan, wantedChunksCount)
|
checkErrChan(ctx, t, errChan, wantedChunksCount)
|
||||||
}
|
}
|
||||||
|
|
@ -90,7 +90,7 @@ func TestDB_SubscribePull_multiple(t *testing.T) {
|
||||||
|
|
||||||
// prepopulate database with some chunks
|
// prepopulate database with some chunks
|
||||||
// before the subscription
|
// before the subscription
|
||||||
uploadRandomChunksBin(t, db, addrs, uploader, &wantedChunksCount, 10)
|
uploadRandomChunksBin(t, db, uploader, addrs, &wantedChunksCount, 10)
|
||||||
|
|
||||||
// set a timeout on subscription
|
// set a timeout on subscription
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
|
@ -110,17 +110,17 @@ func TestDB_SubscribePull_multiple(t *testing.T) {
|
||||||
defer stop()
|
defer stop()
|
||||||
|
|
||||||
// receive and validate addresses from the subscription
|
// receive and validate addresses from the subscription
|
||||||
go checkBin(ctx, bin, ch, addrs, errChan)
|
go readPullSubscriptionBin(ctx, bin, ch, addrs, errChan)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// upload some chunks just after subscribe
|
// upload some chunks just after subscribe
|
||||||
uploadRandomChunksBin(t, db, addrs, uploader, &wantedChunksCount, 5)
|
uploadRandomChunksBin(t, db, uploader, addrs, &wantedChunksCount, 5)
|
||||||
|
|
||||||
time.Sleep(500 * time.Millisecond)
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
|
||||||
// upload some chunks after some short time
|
// upload some chunks after some short time
|
||||||
uploadRandomChunksBin(t, db, addrs, uploader, &wantedChunksCount, 3)
|
uploadRandomChunksBin(t, db, uploader, addrs, &wantedChunksCount, 3)
|
||||||
|
|
||||||
checkErrChan(ctx, t, errChan, wantedChunksCount*subsCount)
|
checkErrChan(ctx, t, errChan, wantedChunksCount*subsCount)
|
||||||
}
|
}
|
||||||
|
|
@ -194,7 +194,7 @@ func TestDB_SubscribePull_since(t *testing.T) {
|
||||||
defer stop()
|
defer stop()
|
||||||
|
|
||||||
// receive and validate addresses from the subscription
|
// receive and validate addresses from the subscription
|
||||||
go checkBin(ctx, bin, ch, addrs, errChan)
|
go readPullSubscriptionBin(ctx, bin, ch, addrs, errChan)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -273,7 +273,7 @@ func TestDB_SubscribePull_until(t *testing.T) {
|
||||||
defer stop()
|
defer stop()
|
||||||
|
|
||||||
// receive and validate addresses from the subscription
|
// receive and validate addresses from the subscription
|
||||||
go checkBin(ctx, bin, ch, addrs, errChan)
|
go readPullSubscriptionBin(ctx, bin, ch, addrs, errChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
// upload some chunks just after subscribe
|
// upload some chunks just after subscribe
|
||||||
|
|
@ -365,7 +365,7 @@ func TestDB_SubscribePull_sinceAndUntil(t *testing.T) {
|
||||||
defer stop()
|
defer stop()
|
||||||
|
|
||||||
// receive and validate addresses from the subscription
|
// receive and validate addresses from the subscription
|
||||||
go checkBin(ctx, bin, ch, addrs, errChan)
|
go readPullSubscriptionBin(ctx, bin, ch, addrs, errChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
// upload some chunks just after subscribe
|
// upload some chunks just after subscribe
|
||||||
|
|
@ -376,7 +376,7 @@ func TestDB_SubscribePull_sinceAndUntil(t *testing.T) {
|
||||||
|
|
||||||
// uploadRandomChunksBin uploads random chunks to database and adds them to
|
// uploadRandomChunksBin uploads random chunks to database and adds them to
|
||||||
// the map of addresses ber bin.
|
// the map of addresses ber bin.
|
||||||
func uploadRandomChunksBin(t *testing.T, db *DB, addrs map[uint8][]storage.Address, uploader *Putter, wantedChunksCount *int, count int) {
|
func uploadRandomChunksBin(t *testing.T, db *DB, uploader *Putter, addrs map[uint8][]storage.Address, wantedChunksCount *int, count int) {
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
chunk := generateRandomChunk()
|
chunk := generateRandomChunk()
|
||||||
|
|
||||||
|
|
@ -395,10 +395,10 @@ func uploadRandomChunksBin(t *testing.T, db *DB, addrs map[uint8][]storage.Addre
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkBin is a helper function that reads all ChunkInfos from a channel and
|
// readPullSubscriptionBin is a helper function that reads all ChunkInfos from a channel and
|
||||||
// sends error to errChan, even if it is nil, to count the number of ChunkInfos
|
// sends error to errChan, even if it is nil, to count the number of ChunkInfos
|
||||||
// returned by the channel.
|
// returned by the channel.
|
||||||
func checkBin(ctx context.Context, bin uint8, ch <-chan ChunkInfo, addrs map[uint8][]storage.Address, errChan chan error) {
|
func readPullSubscriptionBin(ctx context.Context, bin uint8, ch <-chan ChunkInfo, addrs map[uint8][]storage.Address, errChan chan error) {
|
||||||
var i int // address index
|
var i int // address index
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue