github.com/lfch/etcd-io/tests/v3@v3.0.0-20221004140520-eac99acd3e9d/functional/tester/case_failpoints_disk_io.go (about) 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 15 package tester 16 17 import ( 18 "fmt" 19 "strings" 20 21 "github.com/lfch/etcd-io/tests/v3/functional/rpcpb" 22 ) 23 24 const ( 25 diskIOFailpoint = "raftAfterSave" 26 ) 27 28 func failpointDiskIOFailures(clus *Cluster) (ret []Case, err error) { 29 fps, err := failpointPaths(clus.Members[0].FailpointHTTPAddr) 30 if err != nil { 31 return nil, err 32 } 33 var detailDiskIOLatencyFailpointPath string 34 for i := 0; i < len(fps); i++ { 35 if strings.HasSuffix(fps[i], diskIOFailpoint) { 36 detailDiskIOLatencyFailpointPath = fps[i] 37 break 38 } 39 } 40 // create failure objects for diskIOFailpoint 41 fpFails := casesFromDiskIOFailpoint(detailDiskIOLatencyFailpointPath, clus.Tester.FailpointCommands) 42 // wrap in delays so failpoint has time to trigger 43 for i, fpf := range fpFails { 44 fpFails[i] = &caseDelay{ 45 Case: fpf, 46 delayDuration: clus.GetCaseDelayDuration(), 47 } 48 } 49 ret = append(ret, fpFails...) 50 return ret, nil 51 } 52 53 func casesFromDiskIOFailpoint(fp string, failpointCommands []string) (fs []Case) { 54 recov := makeRecoverFailpoint(fp) 55 for _, fcmd := range failpointCommands { 56 inject := makeInjectFailpoint(fp, fcmd) 57 fs = append(fs, []Case{ 58 &caseLeader{ 59 caseByFunc: caseByFunc{ 60 desc: fmt.Sprintf("failpoint %q (leader: %q)", fp, fcmd), 61 rpcpbCase: rpcpb.Case_FAILPOINTS, 62 injectMember: inject, 63 recoverMember: recov, 64 }, 65 last: -1, 66 lead: -1, 67 }, 68 }...) 69 } 70 return fs 71 }