You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.2 KiB

  1. package main
  2. import (
  3. "fmt"
  4. "time"
  5. rpctypes "github.com/tendermint/tendermint/rpc/core/types"
  6. e2e "github.com/tendermint/tendermint/test/e2e/pkg"
  7. )
  8. // Perturbs a running testnet.
  9. func Perturb(testnet *e2e.Testnet) error {
  10. for _, node := range testnet.Nodes {
  11. for _, perturbation := range node.Perturbations {
  12. _, err := PerturbNode(node, perturbation)
  13. if err != nil {
  14. return err
  15. }
  16. time.Sleep(3 * time.Second) // give network some time to recover between each
  17. }
  18. }
  19. return nil
  20. }
  21. // PerturbNode perturbs a node with a given perturbation, returning its status
  22. // after recovering.
  23. func PerturbNode(node *e2e.Node, perturbation e2e.Perturbation) (*rpctypes.ResultStatus, error) {
  24. testnet := node.Testnet
  25. switch perturbation {
  26. case e2e.PerturbationDisconnect:
  27. logger.Info(fmt.Sprintf("Disconnecting node %v...", node.Name))
  28. if err := execDocker("network", "disconnect", testnet.Name+"_"+testnet.Name, node.Name); err != nil {
  29. return nil, err
  30. }
  31. time.Sleep(10 * time.Second)
  32. if err := execDocker("network", "connect", testnet.Name+"_"+testnet.Name, node.Name); err != nil {
  33. return nil, err
  34. }
  35. case e2e.PerturbationKill:
  36. logger.Info(fmt.Sprintf("Killing node %v...", node.Name))
  37. if err := execCompose(testnet.Dir, "kill", "-s", "SIGKILL", node.Name); err != nil {
  38. return nil, err
  39. }
  40. if err := execCompose(testnet.Dir, "start", node.Name); err != nil {
  41. return nil, err
  42. }
  43. case e2e.PerturbationPause:
  44. logger.Info(fmt.Sprintf("Pausing node %v...", node.Name))
  45. if err := execCompose(testnet.Dir, "pause", node.Name); err != nil {
  46. return nil, err
  47. }
  48. time.Sleep(10 * time.Second)
  49. if err := execCompose(testnet.Dir, "unpause", node.Name); err != nil {
  50. return nil, err
  51. }
  52. case e2e.PerturbationRestart:
  53. logger.Info(fmt.Sprintf("Restarting node %v...", node.Name))
  54. if err := execCompose(testnet.Dir, "restart", node.Name); err != nil {
  55. return nil, err
  56. }
  57. default:
  58. return nil, fmt.Errorf("unexpected perturbation %q", perturbation)
  59. }
  60. status, err := waitForNode(node, 0, 20*time.Second)
  61. if err != nil {
  62. return nil, err
  63. }
  64. logger.Info(fmt.Sprintf("Node %v recovered at height %v", node.Name, status.SyncInfo.LatestBlockHeight))
  65. return status, nil
  66. }