From 965014df840471981a4e5341df3c7d2d477c90ab Mon Sep 17 00:00:00 2001 From: Fabio Barone Date: Fri, 20 Jul 2018 11:11:15 -0500 Subject: [PATCH] swarm: fixed syncer tests and snapshot_sync_test --- swarm/network/stream/snapshot_sync_test.go | 17 ++++---- swarm/network/stream/syncer_test.go | 47 +++++++++++----------- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/swarm/network/stream/snapshot_sync_test.go b/swarm/network/stream/snapshot_sync_test.go index 10d3d62f01..e2d85533b4 100644 --- a/swarm/network/stream/snapshot_sync_test.go +++ b/swarm/network/stream/snapshot_sync_test.go @@ -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 } diff --git a/swarm/network/stream/syncer_test.go b/swarm/network/stream/syncer_test.go index a27536e59f..5b59639289 100644 --- a/swarm/network/stream/syncer_test.go +++ b/swarm/network/stream/syncer_test.go @@ -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)