Cleanup removes the root testing (temporary) directory and stops both the Tendermint and API services. It allows other callers to create and start test networks. This method must be called when a test is finished, typically in defer.
()
| 567 | // test networks. This method must be called when a test is finished, typically |
| 568 | // in defer. |
| 569 | func (n *Network) Cleanup() { |
| 570 | defer func() { |
| 571 | lock.Unlock() |
| 572 | n.T.Log("released test network lock") |
| 573 | }() |
| 574 | |
| 575 | n.T.Log("cleaning up test network...") |
| 576 | |
| 577 | for _, v := range n.Validators { |
| 578 | if v.tmNode != nil && v.tmNode.IsRunning() { |
| 579 | _ = v.tmNode.Stop() |
| 580 | } |
| 581 | |
| 582 | if v.api != nil { |
| 583 | // Recover from panic if api.Close() is called before the server fully started |
| 584 | // (cosmos-sdk api.Server.Close panics if listener is nil) |
| 585 | func() { |
| 586 | defer func() { |
| 587 | if r := recover(); r != nil { |
| 588 | n.T.Logf("recovered from api.Close panic: %v", r) |
| 589 | } |
| 590 | }() |
| 591 | _ = v.api.Close() |
| 592 | }() |
| 593 | } |
| 594 | |
| 595 | if v.grpc != nil { |
| 596 | v.grpc.Stop() |
| 597 | if v.grpcWeb != nil { |
| 598 | _ = v.grpcWeb.Close() |
| 599 | } |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | if n.Config.CleanupDir { |
| 604 | _ = os.RemoveAll(n.BaseDir) |
| 605 | } |
| 606 | |
| 607 | n.T.Log("finished cleaning up test network") |
| 608 | } |
| 609 | |
| 610 | // DefaultConfig returns a default configuration suitable for nearly all |
| 611 | // testing requirements. |