Skip to content

Commit

Permalink
Merge pull request #568 from dedis/sim_cleanup_error_567
Browse files Browse the repository at this point in the history
Clean up simulation before returning errors
  • Loading branch information
kc1212 committed Jul 30, 2019
2 parents 7448a4e + 5f0134f commit 297db5c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 2 additions & 0 deletions simul/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ func RunTest(deployP platform.Platform, rc *platform.RunConfig) ([]*monitor.Stat
err := deployP.Start()
if err != nil {
done <- err
return
}

if err = deployP.Wait(); err != nil {
Expand All @@ -243,6 +244,7 @@ func RunTest(deployP platform.Platform, rc *platform.RunConfig) ([]*monitor.Stat
log.Lvl3("Couldn't cleanup platform:", err)
}
done <- err
return
}
done <- nil
}()
Expand Down
6 changes: 3 additions & 3 deletions simul/platform/localhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ func (d *Localhost) Wait() error {
log.Lvl1("Quitting after waiting", wait)
}

err = os.Chdir(d.localDir)
if err != nil {
log.Error("Fail to restore the cwd: " + err.Error())
errCleanup := os.Chdir(d.localDir)
if errCleanup != nil {
log.Error("Fail to restore the cwd: " + errCleanup.Error())
}

monitor.EndAndCleanup()
Expand Down
12 changes: 8 additions & 4 deletions simul/platform/runsimul.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ func Simulate(suite, serverAddress, simul, monitorAddress string) error {
rootSC = sc
}
}

var simError error
if rootSim != nil {
// If this cothority has the root-server, it will start the simulation
log.Lvl2("Starting protocol", simul, "on server", rootSC.Server.ServerIdentity.Address)
Expand Down Expand Up @@ -164,10 +166,7 @@ func Simulate(suite, serverAddress, simul, monitorAddress string) error {
log.Lvl1("Starting new node", simul)

measureNet := monitor.NewCounterIOMeasure("bandwidth_root", rootSC.Server)
err := rootSim.Run(rootSC)
if err != nil {
return errors.New("error from simulation run: " + err.Error())
}
simError = rootSim.Run(rootSC)
measureNet.Record()

// Test if all ServerIdentities are used in the tree, else we'll run into
Expand All @@ -193,6 +192,11 @@ func Simulate(suite, serverAddress, simul, monitorAddress string) error {
if monitorAddress != "" {
monitor.EndAndCleanup()
}

// Give a chance to the simulation to stop the servers and clean up but returns the simulation error anyway.
if simError != nil {
return errors.New("error from simulation run: " + simError.Error())
}
return nil
}

Expand Down

0 comments on commit 297db5c

Please sign in to comment.