failure_case_network_slow.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 newFailureDelayPeerPortTxRxLeader(clus *Cluster) Failure {
  47. ff := failureByFunc{
  48. failureCase: rpcpb.FailureCase_DELAY_PEER_PORT_TX_RX_LEADER,
  49. injectMember: injectDelayPeerPortTxRx,
  50. recoverMember: recoverDelayPeerPortTxRx,
  51. }
  52. f := &failureLeader{ff, -1, -1}
  53. return &failureDelay{
  54. Failure: f,
  55. delayDuration: clus.GetFailureDelayDuration(),
  56. }
  57. }
  58. func newFailureDelayPeerPortTxRxAll(clus *Cluster) Failure {
  59. f := &failureAll{
  60. failureCase: rpcpb.FailureCase_DELAY_PEER_PORT_TX_RX_ALL,
  61. injectMember: injectDelayPeerPortTxRx,
  62. recoverMember: recoverDelayPeerPortTxRx,
  63. }
  64. return &failureDelay{
  65. Failure: f,
  66. delayDuration: clus.GetFailureDelayDuration(),
  67. }
  68. }