|
|
@@ -20,13 +20,11 @@ import (
|
|
|
"bytes"
|
|
|
"context"
|
|
|
"fmt"
|
|
|
- "os"
|
|
|
"sync"
|
|
|
"testing"
|
|
|
"time"
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/swarm/storage"
|
|
|
- "github.com/ethereum/go-ethereum/swarm/testutil"
|
|
|
)
|
|
|
|
|
|
// TestDB_SubscribePull uploads some chunks before and after
|
|
|
@@ -34,12 +32,6 @@ import (
|
|
|
// all addresses are received in the right order
|
|
|
// for expected proximity order bins.
|
|
|
func TestDB_SubscribePull(t *testing.T) {
|
|
|
-
|
|
|
- if testutil.RaceEnabled && os.Getenv("TRAVIS") == "true" {
|
|
|
- t.Skip("does not complete with -race on Travis")
|
|
|
- // Note: related ticket TODO
|
|
|
- }
|
|
|
-
|
|
|
db, cleanupFunc := newTestDB(t, nil)
|
|
|
defer cleanupFunc()
|
|
|
|
|
|
@@ -87,12 +79,6 @@ func TestDB_SubscribePull(t *testing.T) {
|
|
|
// validates if all addresses are received in the right order
|
|
|
// for expected proximity order bins.
|
|
|
func TestDB_SubscribePull_multiple(t *testing.T) {
|
|
|
-
|
|
|
- if testutil.RaceEnabled && os.Getenv("TRAVIS") == "true" {
|
|
|
- t.Skip("does not complete with -race on Travis")
|
|
|
- // Note: related ticket TODO
|
|
|
- }
|
|
|
-
|
|
|
db, cleanupFunc := newTestDB(t, nil)
|
|
|
defer cleanupFunc()
|
|
|
|
|
|
@@ -146,12 +132,6 @@ func TestDB_SubscribePull_multiple(t *testing.T) {
|
|
|
// and validates if all expected addresses are received in the
|
|
|
// right order for expected proximity order bins.
|
|
|
func TestDB_SubscribePull_since(t *testing.T) {
|
|
|
-
|
|
|
- if testutil.RaceEnabled && os.Getenv("TRAVIS") == "true" {
|
|
|
- t.Skip("does not complete with -race on Travis")
|
|
|
- // Note: related ticket TODO
|
|
|
- }
|
|
|
-
|
|
|
db, cleanupFunc := newTestDB(t, nil)
|
|
|
defer cleanupFunc()
|
|
|
|
|
|
@@ -171,6 +151,9 @@ func TestDB_SubscribePull_since(t *testing.T) {
|
|
|
})()
|
|
|
|
|
|
uploadRandomChunks := func(count int, wanted bool) (last map[uint8]ChunkDescriptor) {
|
|
|
+ addrsMu.Lock()
|
|
|
+ defer addrsMu.Unlock()
|
|
|
+
|
|
|
last = make(map[uint8]ChunkDescriptor)
|
|
|
for i := 0; i < count; i++ {
|
|
|
chunk := generateRandomChunk()
|
|
|
@@ -182,7 +165,6 @@ func TestDB_SubscribePull_since(t *testing.T) {
|
|
|
|
|
|
bin := db.po(chunk.Address())
|
|
|
|
|
|
- addrsMu.Lock()
|
|
|
if _, ok := addrs[bin]; !ok {
|
|
|
addrs[bin] = make([]storage.Address, 0)
|
|
|
}
|
|
|
@@ -190,7 +172,6 @@ func TestDB_SubscribePull_since(t *testing.T) {
|
|
|
addrs[bin] = append(addrs[bin], chunk.Address())
|
|
|
wantedChunksCount++
|
|
|
}
|
|
|
- addrsMu.Unlock()
|
|
|
|
|
|
lastTimestampMu.RLock()
|
|
|
storeTimestamp := lastTimestamp
|
|
|
@@ -242,12 +223,6 @@ func TestDB_SubscribePull_since(t *testing.T) {
|
|
|
// and validates if all expected addresses are received in the
|
|
|
// right order for expected proximity order bins.
|
|
|
func TestDB_SubscribePull_until(t *testing.T) {
|
|
|
-
|
|
|
- if testutil.RaceEnabled && os.Getenv("TRAVIS") == "true" {
|
|
|
- t.Skip("does not complete with -race on Travis")
|
|
|
- // Note: related ticket TODO
|
|
|
- }
|
|
|
-
|
|
|
db, cleanupFunc := newTestDB(t, nil)
|
|
|
defer cleanupFunc()
|
|
|
|
|
|
@@ -267,6 +242,9 @@ func TestDB_SubscribePull_until(t *testing.T) {
|
|
|
})()
|
|
|
|
|
|
uploadRandomChunks := func(count int, wanted bool) (last map[uint8]ChunkDescriptor) {
|
|
|
+ addrsMu.Lock()
|
|
|
+ defer addrsMu.Unlock()
|
|
|
+
|
|
|
last = make(map[uint8]ChunkDescriptor)
|
|
|
for i := 0; i < count; i++ {
|
|
|
chunk := generateRandomChunk()
|
|
|
@@ -278,7 +256,6 @@ func TestDB_SubscribePull_until(t *testing.T) {
|
|
|
|
|
|
bin := db.po(chunk.Address())
|
|
|
|
|
|
- addrsMu.Lock()
|
|
|
if _, ok := addrs[bin]; !ok {
|
|
|
addrs[bin] = make([]storage.Address, 0)
|
|
|
}
|
|
|
@@ -286,7 +263,6 @@ func TestDB_SubscribePull_until(t *testing.T) {
|
|
|
addrs[bin] = append(addrs[bin], chunk.Address())
|
|
|
wantedChunksCount++
|
|
|
}
|
|
|
- addrsMu.Unlock()
|
|
|
|
|
|
lastTimestampMu.RLock()
|
|
|
storeTimestamp := lastTimestamp
|
|
|
@@ -337,12 +313,6 @@ func TestDB_SubscribePull_until(t *testing.T) {
|
|
|
// and until arguments, and validates if all expected addresses
|
|
|
// are received in the right order for expected proximity order bins.
|
|
|
func TestDB_SubscribePull_sinceAndUntil(t *testing.T) {
|
|
|
-
|
|
|
- if testutil.RaceEnabled && os.Getenv("TRAVIS") == "true" {
|
|
|
- t.Skip("does not complete with -race on Travis")
|
|
|
- // Note: related ticket TODO
|
|
|
- }
|
|
|
-
|
|
|
db, cleanupFunc := newTestDB(t, nil)
|
|
|
defer cleanupFunc()
|
|
|
|
|
|
@@ -362,6 +332,9 @@ func TestDB_SubscribePull_sinceAndUntil(t *testing.T) {
|
|
|
})()
|
|
|
|
|
|
uploadRandomChunks := func(count int, wanted bool) (last map[uint8]ChunkDescriptor) {
|
|
|
+ addrsMu.Lock()
|
|
|
+ defer addrsMu.Unlock()
|
|
|
+
|
|
|
last = make(map[uint8]ChunkDescriptor)
|
|
|
for i := 0; i < count; i++ {
|
|
|
chunk := generateRandomChunk()
|
|
|
@@ -373,7 +346,6 @@ func TestDB_SubscribePull_sinceAndUntil(t *testing.T) {
|
|
|
|
|
|
bin := db.po(chunk.Address())
|
|
|
|
|
|
- addrsMu.Lock()
|
|
|
if _, ok := addrs[bin]; !ok {
|
|
|
addrs[bin] = make([]storage.Address, 0)
|
|
|
}
|
|
|
@@ -381,7 +353,6 @@ func TestDB_SubscribePull_sinceAndUntil(t *testing.T) {
|
|
|
addrs[bin] = append(addrs[bin], chunk.Address())
|
|
|
wantedChunksCount++
|
|
|
}
|
|
|
- addrsMu.Unlock()
|
|
|
|
|
|
lastTimestampMu.RLock()
|
|
|
storeTimestamp := lastTimestamp
|
|
|
@@ -442,6 +413,9 @@ func TestDB_SubscribePull_sinceAndUntil(t *testing.T) {
|
|
|
// uploadRandomChunksBin uploads random chunks to database and adds them to
|
|
|
// the map of addresses ber bin.
|
|
|
func uploadRandomChunksBin(t *testing.T, db *DB, uploader *Putter, addrs map[uint8][]storage.Address, addrsMu *sync.Mutex, wantedChunksCount *int, count int) {
|
|
|
+ addrsMu.Lock()
|
|
|
+ defer addrsMu.Unlock()
|
|
|
+
|
|
|
for i := 0; i < count; i++ {
|
|
|
chunk := generateRandomChunk()
|
|
|
|
|
|
@@ -450,13 +424,11 @@ func uploadRandomChunksBin(t *testing.T, db *DB, uploader *Putter, addrs map[uin
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
|
|
|
- addrsMu.Lock()
|
|
|
bin := db.po(chunk.Address())
|
|
|
if _, ok := addrs[bin]; !ok {
|
|
|
addrs[bin] = make([]storage.Address, 0)
|
|
|
}
|
|
|
addrs[bin] = append(addrs[bin], chunk.Address())
|
|
|
- addrsMu.Unlock()
|
|
|
|
|
|
*wantedChunksCount++
|
|
|
}
|
|
|
@@ -473,19 +445,24 @@ func readPullSubscriptionBin(ctx context.Context, bin uint8, ch <-chan ChunkDesc
|
|
|
if !ok {
|
|
|
return
|
|
|
}
|
|
|
+ var err error
|
|
|
addrsMu.Lock()
|
|
|
if i+1 > len(addrs[bin]) {
|
|
|
- errChan <- fmt.Errorf("got more chunk addresses %v, then expected %v, for bin %v", i+1, len(addrs[bin]), bin)
|
|
|
+ err = fmt.Errorf("got more chunk addresses %v, then expected %v, for bin %v", i+1, len(addrs[bin]), bin)
|
|
|
+ } else {
|
|
|
+ want := addrs[bin][i]
|
|
|
+ if !bytes.Equal(got.Address, want) {
|
|
|
+ err = fmt.Errorf("got chunk address %v in bin %v %s, want %s", i, bin, got.Address.Hex(), want)
|
|
|
+ }
|
|
|
}
|
|
|
- want := addrs[bin][i]
|
|
|
addrsMu.Unlock()
|
|
|
- var err error
|
|
|
- if !bytes.Equal(got.Address, want) {
|
|
|
- err = fmt.Errorf("got chunk address %v in bin %v %s, want %s", i, bin, got.Address.Hex(), want)
|
|
|
- }
|
|
|
i++
|
|
|
// send one and only one error per received address
|
|
|
- errChan <- err
|
|
|
+ select {
|
|
|
+ case errChan <- err:
|
|
|
+ case <-ctx.Done():
|
|
|
+ return
|
|
|
+ }
|
|
|
case <-ctx.Done():
|
|
|
return
|
|
|
}
|