swarm/network: style fix

This commit is contained in:
Vlad 2019-03-21 18:17:08 +04:00
parent f86e5ddf71
commit 8badaa55ca
3 changed files with 10 additions and 27 deletions

View file

@ -223,25 +223,19 @@ func (s *Simulation) UploadSnapshot(ctx context.Context, snapshotFile string, op
if err != nil { if err != nil {
return err return err
} }
defer func() { defer f.Close()
err := f.Close()
if err != nil {
log.Error("Error closing snapshot file", "err", err)
}
}()
jsonbyte, err := ioutil.ReadAll(f) jsonbyte, err := ioutil.ReadAll(f)
if err != nil { if err != nil {
return err return err
} }
var snap simulations.Snapshot var snap simulations.Snapshot
err = json.Unmarshal(jsonbyte, &snap) if err := json.Unmarshal(jsonbyte, &snap); err != nil {
if err != nil {
return err return err
} }
//the snapshot probably has the property EnableMsgEvents not set //the snapshot probably has the property EnableMsgEvents not set
//just in case, set it to true! //set it to true (we need this to wait for messages before uploading)
//(we need this to wait for messages before uploading)
for i := range snap.Nodes { for i := range snap.Nodes {
snap.Nodes[i].Node.Config.EnableMsgEvents = true snap.Nodes[i].Node.Config.EnableMsgEvents = true
snap.Nodes[i].Node.Config.Services = s.serviceNames 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...") if err := s.Net.Load(&snap); err != nil {
//now we can load the snapshot
err = s.Net.Load(&snap)
if err != nil {
return err return err
} }
return s.WaitTillSnapshotRecreated(ctx, &snap)
err = s.WaitTillSnapshotRecreated(ctx, &snap)
if err == nil {
log.Info("Snapshot loaded")
} else {
log.Warn("Snapshot load failed", "error", err.Error())
}
return err
} }
// StartNode starts a node by NodeID. // StartNode starts a node by NodeID.

View file

@ -297,7 +297,7 @@ func TestUploadSnapshot(t *testing.T) {
nodeCount := 16 nodeCount := 16
log.Debug("Uploading snapshot") log.Debug("Uploading snapshot")
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel() defer cancel()
err := s.UploadSnapshot(ctx, fmt.Sprintf("../stream/testing/snapshot_%d.json", nodeCount)) err := s.UploadSnapshot(ctx, fmt.Sprintf("../stream/testing/snapshot_%d.json", nodeCount))
if err != nil { if err != nil {

View file

@ -1257,10 +1257,10 @@ func TestGetSubscriptionsRPC(t *testing.T) {
simulation.NewPeerEventsFilter().ReceivedMessages().Protocol("stream").MsgCode(subscribeMsgCode), 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() defer cancel()
err := sim.UploadSnapshot(ctx, fmt.Sprintf("testing/snapshot_%d.json", nodeCount)) filename := fmt.Sprintf("testing/snapshot_%d.json", nodeCount)
if err != nil { if err := sim.UploadSnapshot(ctx, filename); err != nil {
t.Fatal(err) t.Fatal(err)
} }