swarm: fixed syncer tests and snapshot_sync_test

This commit is contained in:
Fabio Barone 2018-07-20 11:11:15 -05:00
parent 25d20af3a4
commit 965014df84
2 changed files with 30 additions and 34 deletions

View file

@ -103,7 +103,7 @@ func TestSyncingViaRPC(t *testing.T) {
//run more test combinations
if *longrunning {
chnkCnt = []int{1, 8, 32, 256, 1024}
nodeCnt = []int{16, 32, 64, 128, 256}
nodeCnt = []int{32, 16}
} else {
//default test
chnkCnt = []int{4, 32}
@ -158,8 +158,6 @@ func testSyncing(t *testing.T, chunkCount int, nodeCount int) {
log.Info("Initializing test config")
ctx := context.Background()
conf := &synctestConfig{}
//map of discover ID to indexes of chunks expected at that ID
conf.idToChunksMap = make(map[discover.NodeID][]int)
@ -173,6 +171,9 @@ func testSyncing(t *testing.T, chunkCount int, nodeCount int) {
t.Fatal(err)
}
ctx, cancelSimRun := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancelSimRun()
result := sim.Run(ctx, func(ctx context.Context, sim *simulation.Simulation) error {
nodeIDs := sim.UpNodeIDs()
for _, n := range nodeIDs {
@ -327,12 +328,8 @@ func runSyncTest(chunkCount int, nodeCount int) error {
})
defer sim.Close()
log.Info("Initializing test config")
_, err := sim.AddNodesAndConnectFull(3)
if err != nil {
return err
}
ctx := context.Background()
ctx, cancelSimRun := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancelSimRun()
conf := &synctestConfig{}
//map of discover ID to indexes of chunks expected at that ID
@ -342,7 +339,7 @@ func runSyncTest(chunkCount int, nodeCount int) error {
//array where the generated chunk hashes will be stored
conf.hashes = make([]storage.Address, 0)
err = sim.UploadSnapshot(fmt.Sprintf("testing/snapshot_%d.json", nodeCount))
err := sim.UploadSnapshot(fmt.Sprintf("testing/snapshot_%d.json", nodeCount))
if err != nil {
return err
}

View file

@ -142,27 +142,6 @@ func testSyncBetweenNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck
nodeIndex[id] = i
}
// collect hashes in po 1 bin for each node
hashes := make([][]storage.Address, nodes)
totalHashes := 0
hashCounts := make([]int, nodes)
for i := nodes - 1; i >= 0; i-- {
if i < nodes-1 {
hashCounts[i] = hashCounts[i+1]
}
item, ok := sim.NodeItem(nodeIDs[i], bucketKeyDB)
if !ok {
return fmt.Errorf("No DB")
}
db := item.(*storage.DBAPI)
db.Iterator(0, math.MaxUint64, po, func(addr storage.Address, index uint64) bool {
hashes[i] = append(hashes[i], addr)
totalHashes++
hashCounts[i]++
return true
})
}
disconnections := sim.PeerEvents(
context.Background(),
sim.NodeIDs(),
@ -190,7 +169,7 @@ func testSyncBetweenNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck
if err != nil {
return err
}
if j > 0 {
if j > 0 || nodes == 2 {
item, ok := sim.NodeItem(nodeIDs[j], bucketKeyFileStore)
if !ok {
return fmt.Errorf("No filestore")
@ -211,6 +190,26 @@ func testSyncBetweenNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck
}
}
// collect hashes in po 1 bin for each node
hashes := make([][]storage.Address, nodes)
totalHashes := 0
hashCounts := make([]int, nodes)
for i := nodes - 1; i >= 0; i-- {
if i < nodes-1 {
hashCounts[i] = hashCounts[i+1]
}
item, ok := sim.NodeItem(nodeIDs[i], bucketKeyDB)
if !ok {
return fmt.Errorf("No DB")
}
db := item.(*storage.DBAPI)
db.Iterator(0, math.MaxUint64, po, func(addr storage.Address, index uint64) bool {
hashes[i] = append(hashes[i], addr)
totalHashes++
hashCounts[i]++
return true
})
}
var total, found int
for _, node := range nodeIDs {
i := nodeIndex[node]
@ -236,8 +235,8 @@ func testSyncBetweenNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck
}
log.Debug("sync check", "node", node, "index", i, "bin", po, "found", found, "total", total)
}
//TODO: This test should not get total = 0? It currently does!
if total == found {
log.Error("total", "total", total)
if total == found && total > 0 {
return nil
}
return fmt.Errorf("Total not equallying found: total is %d", total)