diff --git a/swarm/network/simulation/node.go b/swarm/network/simulation/node.go index 831714efd6..b9d719eeec 100644 --- a/swarm/network/simulation/node.go +++ b/swarm/network/simulation/node.go @@ -223,25 +223,19 @@ func (s *Simulation) UploadSnapshot(ctx context.Context, snapshotFile string, op if err != nil { return err } - defer func() { - err := f.Close() - if err != nil { - log.Error("Error closing snapshot file", "err", err) - } - }() + defer f.Close() + jsonbyte, err := ioutil.ReadAll(f) if err != nil { return err } var snap simulations.Snapshot - err = json.Unmarshal(jsonbyte, &snap) - if err != nil { + if err := json.Unmarshal(jsonbyte, &snap); err != nil { return err } //the snapshot probably has the property EnableMsgEvents not set - //just in case, set it to true! - //(we need this to wait for messages before uploading) + //set it to true (we need this to wait for messages before uploading) for i := range snap.Nodes { snap.Nodes[i].Node.Config.EnableMsgEvents = true snap.Nodes[i].Node.Config.Services = s.serviceNames @@ -250,21 +244,10 @@ func (s *Simulation) UploadSnapshot(ctx context.Context, snapshotFile string, op } } - log.Info("Waiting for p2p connections to be established...") - - //now we can load the snapshot - err = s.Net.Load(&snap) - if err != nil { + if err := s.Net.Load(&snap); err != nil { return err } - - err = s.WaitTillSnapshotRecreated(ctx, &snap) - if err == nil { - log.Info("Snapshot loaded") - } else { - log.Warn("Snapshot load failed", "error", err.Error()) - } - return err + return s.WaitTillSnapshotRecreated(ctx, &snap) } // StartNode starts a node by NodeID. diff --git a/swarm/network/simulation/node_test.go b/swarm/network/simulation/node_test.go index fe657a57ce..e1e20a0f13 100644 --- a/swarm/network/simulation/node_test.go +++ b/swarm/network/simulation/node_test.go @@ -297,7 +297,7 @@ func TestUploadSnapshot(t *testing.T) { nodeCount := 16 log.Debug("Uploading snapshot") - ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() err := s.UploadSnapshot(ctx, fmt.Sprintf("../stream/testing/snapshot_%d.json", nodeCount)) if err != nil { diff --git a/swarm/network/stream/streamer_test.go b/swarm/network/stream/streamer_test.go index 4df59508cb..bdd3087bbc 100644 --- a/swarm/network/stream/streamer_test.go +++ b/swarm/network/stream/streamer_test.go @@ -1257,10 +1257,10 @@ func TestGetSubscriptionsRPC(t *testing.T) { simulation.NewPeerEventsFilter().ReceivedMessages().Protocol("stream").MsgCode(subscribeMsgCode), ) - ctx, cancel := context.WithTimeout(context.Background(), time.Second*120) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) defer cancel() - err := sim.UploadSnapshot(ctx, fmt.Sprintf("testing/snapshot_%d.json", nodeCount)) - if err != nil { + filename := fmt.Sprintf("testing/snapshot_%d.json", nodeCount) + if err := sim.UploadSnapshot(ctx, filename); err != nil { t.Fatal(err) }