Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Commit

Permalink
test: fix invalid failpoint and integration test (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
glorv authored Jan 18, 2021
1 parent deb5243 commit 90dbfe3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
40 changes: 29 additions & 11 deletions lightning/backend/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,34 @@ loopWrite:
for errCnt < maxRetryTimes {
log.L().Debug("ingest meta", zap.Reflect("meta", meta))
var resp *sst.IngestResponse
resp, err = local.Ingest(ctx, meta, region)
failpoint.Inject("FailIngestMeta", func(val failpoint.Value) {
// only inject the error once
switch val.(string) {
case "notleader":
resp = &sst.IngestResponse{
Error: &errorpb.Error{
NotLeader: &errorpb.NotLeader{
RegionId: region.Region.Id,
Leader: region.Leader,
},
},
}
case "epochnotmatch":
resp = &sst.IngestResponse{
Error: &errorpb.Error{
EpochNotMatch: &errorpb.EpochNotMatch{
CurrentRegions: []*metapb.Region{region.Region},
},
},
}
}
if resp != nil {
err = nil
}
})
if resp == nil {
resp, err = local.Ingest(ctx, meta, region)
}
if err != nil {
if errors.Cause(err) == context.Canceled {
return nil, err
Expand All @@ -1055,16 +1082,7 @@ loopWrite:
errCnt++
continue
}
failpoint.Inject("FailIngestMeta", func(val failpoint.Value) {
switch val.(string) {
case "notleader":
resp.Error.NotLeader = &errorpb.NotLeader{
RegionId: region.Region.Id, Leader: region.Leader}
case "epochnotmatch":
resp.Error.EpochNotMatch = &errorpb.EpochNotMatch{
CurrentRegions: []*metapb.Region{region.Region}}
}
})

var retryTy retryType
var newRegion *split.RegionInfo
retryTy, newRegion, err = local.isIngestRetryable(ctx, resp, region, meta)
Expand Down
4 changes: 2 additions & 2 deletions tests/local_backend/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ENGINE_COUNT=6
rm -f "$TEST_DIR/lightning-local.log"
rm -f "/tmp/tidb_lightning_checkpoint_local_backend_test.pb"
run_sql 'DROP DATABASE IF EXISTS cpeng;'
export GO_FAILPOINTS='github.com/pingcap/tidb-lightning/lightning/backend/local/FailIngestMeta=return("notleader")'
export GO_FAILPOINTS='github.com/pingcap/tidb-lightning/lightning/backend/FailIngestMeta=1*return("notleader")'

run_lightning --backend local --enable-checkpoint=1 --log-file "$TEST_DIR/lightning-local.log" --config "tests/$TEST_NAME/config.toml"

Expand All @@ -40,7 +40,7 @@ check_contains 'sum(c): 46'
run_sql 'DROP DATABASE cpeng;'
rm -f "/tmp/tidb_lightning_checkpoint_local_backend_test.pb"

export GO_FAILPOINTS='github.com/pingcap/tidb-lightning/lightning/backend/local/FailIngestMeta=return("epochnotmatch")'
export GO_FAILPOINTS='github.com/pingcap/tidb-lightning/lightning/backend/FailIngestMeta=2*return("epochnotmatch")'

run_lightning --backend local --enable-checkpoint=1 --log-file "$TEST_DIR/lightning-local.log" --config "tests/$TEST_NAME/config.toml"

Expand Down

0 comments on commit 90dbfe3

Please sign in to comment.