failure_case_network_delay.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Copyright 2018 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package tester
  15. import (
  16. "time"
  17. "github.com/coreos/etcd/tools/functional-tester/rpcpb"
  18. )
  19. const (
  20. // Wait more when it recovers from slow network, because network layer
  21. // needs extra time to propagate traffic control (tc command) change.
  22. // Otherwise, we get different hash values from the previous revision.
  23. // For more detail, please see https://github.com/coreos/etcd/issues/5121.
  24. waitRecover = 5 * time.Second
  25. )
  26. func injectDelayPeerPortTxRx(clus *Cluster, idx int) error {
  27. return clus.sendOperation(idx, rpcpb.Operation_DelayPeerPortTxRx)
  28. }
  29. func recoverDelayPeerPortTxRx(clus *Cluster, idx int) error {
  30. err := clus.sendOperation(idx, rpcpb.Operation_UndelayPeerPortTxRx)
  31. time.Sleep(waitRecover)
  32. return err
  33. }
  34. func newFailureDelayPeerPortTxRxOneFollower(clus *Cluster) Failure {
  35. ff := failureByFunc{
  36. failureCase: rpcpb.FailureCase_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER,
  37. injectMember: injectDelayPeerPortTxRx,
  38. recoverMember: recoverDelayPeerPortTxRx,
  39. }
  40. f := &failureFollower{ff, -1, -1}
  41. return &failureDelay{
  42. Failure: f,
  43. delayDuration: clus.GetFailureDelayDuration(),
  44. }
  45. }
  46. func newFailureDelayPeerPortTxRxOneFollowerUntilTriggerSnapshot() Failure {
  47. ff := failureByFunc{
  48. failureCase: rpcpb.FailureCase_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT,
  49. injectMember: injectDelayPeerPortTxRx,
  50. recoverMember: recoverDelayPeerPortTxRx,
  51. }
  52. f := &failureFollower{ff, -1, -1}
  53. return &failureUntilSnapshot{
  54. failureCase: rpcpb.FailureCase_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT,
  55. Failure: f,
  56. }
  57. }
  58. func newFailureDelayPeerPortTxRxLeader(clus *Cluster) Failure {
  59. ff := failureByFunc{
  60. failureCase: rpcpb.FailureCase_DELAY_PEER_PORT_TX_RX_LEADER,
  61. injectMember: injectDelayPeerPortTxRx,
  62. recoverMember: recoverDelayPeerPortTxRx,
  63. }
  64. f := &failureLeader{ff, -1, -1}
  65. return &failureDelay{
  66. Failure: f,
  67. delayDuration: clus.GetFailureDelayDuration(),
  68. }
  69. }
  70. func newFailureDelayPeerPortTxRxLeaderUntilTriggerSnapshot() Failure {
  71. ff := failureByFunc{
  72. failureCase: rpcpb.FailureCase_DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT,
  73. injectMember: injectDelayPeerPortTxRx,
  74. recoverMember: recoverDelayPeerPortTxRx,
  75. }
  76. f := &failureLeader{ff, -1, -1}
  77. return &failureUntilSnapshot{
  78. failureCase: rpcpb.FailureCase_DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT,
  79. Failure: f,
  80. }
  81. }
  82. func newFailureDelayPeerPortTxRxQuorum(clus *Cluster) Failure {
  83. f := &failureQuorum{
  84. failureCase: rpcpb.FailureCase_DELAY_PEER_PORT_TX_RX_QUORUM,
  85. injectMember: injectDelayPeerPortTxRx,
  86. recoverMember: recoverDelayPeerPortTxRx,
  87. }
  88. return &failureDelay{
  89. Failure: f,
  90. delayDuration: clus.GetFailureDelayDuration(),
  91. }
  92. }
  93. func newFailureDelayPeerPortTxRxAll(clus *Cluster) Failure {
  94. f := &failureAll{
  95. failureCase: rpcpb.FailureCase_DELAY_PEER_PORT_TX_RX_ALL,
  96. injectMember: injectDelayPeerPortTxRx,
  97. recoverMember: recoverDelayPeerPortTxRx,
  98. }
  99. return &failureDelay{
  100. Failure: f,
  101. delayDuration: clus.GetFailureDelayDuration(),
  102. }
  103. }