mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Move failpoints to separate package
Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
This commit is contained in:
parent
569640f278
commit
d6e376b6c6
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package robustness
|
||||
package failpoint
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -80,10 +80,10 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func pickRandomFailpoint(t *testing.T, clus *e2e.EtcdProcessCluster) Failpoint {
|
||||
func PickRandom(t *testing.T, clus *e2e.EtcdProcessCluster) Failpoint {
|
||||
availableFailpoints := make([]Failpoint, 0, len(allFailpoints))
|
||||
for _, failpoint := range allFailpoints {
|
||||
err := validateFailpoint(clus, failpoint)
|
||||
err := Validate(clus, failpoint)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@ -96,7 +96,7 @@ func pickRandomFailpoint(t *testing.T, clus *e2e.EtcdProcessCluster) Failpoint {
|
||||
return availableFailpoints[rand.Int()%len(availableFailpoints)]
|
||||
}
|
||||
|
||||
func validateFailpoint(clus *e2e.EtcdProcessCluster, failpoint Failpoint) error {
|
||||
func Validate(clus *e2e.EtcdProcessCluster, failpoint Failpoint) error {
|
||||
for _, proc := range clus.Procs {
|
||||
if !failpoint.Available(*clus.Cfg, proc) {
|
||||
return fmt.Errorf("failpoint %q not available on %s", failpoint.Name(), proc.Config().Name)
|
||||
@ -105,7 +105,7 @@ func validateFailpoint(clus *e2e.EtcdProcessCluster, failpoint Failpoint) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func injectFailpoints(ctx context.Context, t *testing.T, lg *zap.Logger, clus *e2e.EtcdProcessCluster, failpoint Failpoint) {
|
||||
func Inject(ctx context.Context, t *testing.T, lg *zap.Logger, clus *e2e.EtcdProcessCluster, failpoint Failpoint) {
|
||||
ctx, cancel := context.WithTimeout(ctx, triggerTimeout)
|
||||
defer cancel()
|
||||
var err error
|
@ -26,6 +26,7 @@ import (
|
||||
|
||||
"go.etcd.io/etcd/api/v3/version"
|
||||
"go.etcd.io/etcd/tests/v3/framework/e2e"
|
||||
"go.etcd.io/etcd/tests/v3/robustness/failpoint"
|
||||
"go.etcd.io/etcd/tests/v3/robustness/identity"
|
||||
"go.etcd.io/etcd/tests/v3/robustness/model"
|
||||
"go.etcd.io/etcd/tests/v3/robustness/report"
|
||||
@ -105,7 +106,7 @@ func TestRobustness(t *testing.T) {
|
||||
}
|
||||
scenarios = append(scenarios, testScenario{
|
||||
name: "Issue14370",
|
||||
failpoint: RaftBeforeSavePanic,
|
||||
failpoint: failpoint.RaftBeforeSavePanic,
|
||||
profile: traffic.LowTraffic,
|
||||
traffic: traffic.EtcdPutDeleteLease,
|
||||
cluster: *e2e.NewConfig(
|
||||
@ -115,7 +116,7 @@ func TestRobustness(t *testing.T) {
|
||||
})
|
||||
scenarios = append(scenarios, testScenario{
|
||||
name: "Issue14685",
|
||||
failpoint: DefragBeforeCopyPanic,
|
||||
failpoint: failpoint.DefragBeforeCopyPanic,
|
||||
profile: traffic.LowTraffic,
|
||||
traffic: traffic.EtcdPutDeleteLease,
|
||||
cluster: *e2e.NewConfig(
|
||||
@ -125,7 +126,7 @@ func TestRobustness(t *testing.T) {
|
||||
})
|
||||
scenarios = append(scenarios, testScenario{
|
||||
name: "Issue13766",
|
||||
failpoint: KillFailpoint,
|
||||
failpoint: failpoint.KillFailpoint,
|
||||
profile: traffic.HighTrafficProfile,
|
||||
traffic: traffic.EtcdPut,
|
||||
cluster: *e2e.NewConfig(
|
||||
@ -147,7 +148,7 @@ func TestRobustness(t *testing.T) {
|
||||
if v.Compare(version.V3_6) >= 0 {
|
||||
scenarios = append(scenarios, testScenario{
|
||||
name: "Issue15271",
|
||||
failpoint: BlackholeUntilSnapshot,
|
||||
failpoint: failpoint.BlackholeUntilSnapshot,
|
||||
profile: traffic.HighTrafficProfile,
|
||||
traffic: traffic.EtcdPut,
|
||||
cluster: *e2e.NewConfig(
|
||||
@ -170,7 +171,7 @@ func TestRobustness(t *testing.T) {
|
||||
|
||||
type testScenario struct {
|
||||
name string
|
||||
failpoint Failpoint
|
||||
failpoint failpoint.Failpoint
|
||||
cluster e2e.EtcdProcessClusterConfig
|
||||
traffic traffic.Traffic
|
||||
profile traffic.Profile
|
||||
@ -187,9 +188,9 @@ func testRobustness(ctx context.Context, t *testing.T, lg *zap.Logger, s testSce
|
||||
defer report.Cluster.Close()
|
||||
|
||||
if s.failpoint == nil {
|
||||
s.failpoint = pickRandomFailpoint(t, report.Cluster)
|
||||
s.failpoint = failpoint.PickRandom(t, report.Cluster)
|
||||
} else {
|
||||
err = validateFailpoint(report.Cluster, s.failpoint)
|
||||
err = failpoint.Validate(report.Cluster, s.failpoint)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -224,7 +225,7 @@ func (s testScenario) run(ctx context.Context, t *testing.T, lg *zap.Logger, clu
|
||||
ids := identity.NewIdProvider()
|
||||
g.Go(func() error {
|
||||
defer close(finishTraffic)
|
||||
injectFailpoints(ctx, t, lg, clus, s.failpoint)
|
||||
failpoint.Inject(ctx, t, lg, clus, s.failpoint)
|
||||
time.Sleep(time.Second)
|
||||
return nil
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user