Skip to content

Commit

Permalink
update panic test
Browse files Browse the repository at this point in the history
  • Loading branch information
fzhedu committed Dec 25, 2019
1 parent c2d17ac commit d090ccc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion executor/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (e *ExplainExec) Next(ctx context.Context, req *chunk.Chunk) error {
func (e *ExplainExec) generateExplainInfo(ctx context.Context) (rows [][]string, err error) {
closed := false
defer func() {
if !closed {
if !closed && e.analyzeExec != nil {
err = e.analyzeExec.Close()
closed = true
}
Expand Down
7 changes: 4 additions & 3 deletions executor/explain_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,17 @@ func TestExplainAnalyzeInvokeNextAndClose(t *testing.T) {
explain: nil,
}
// mockErrorOperator returns errors
explainExec.analyzeExec = &mockErrorOperator{baseExec, false, false}
mockOper := mockErrorOperator{baseExec, false, false}
explainExec.analyzeExec = &mockOper
tmpCtx := context.Background()
_, err := explainExec.generateExplainInfo(tmpCtx)

expectedStr := "next error, close error"
if err.Error() != expectedStr {
if err.Error() != expectedStr || !mockOper.closed {
t.Errorf(err.Error())
}
// mockErrorOperator panic
mockOper := mockErrorOperator{baseExec, true, false}
mockOper = mockErrorOperator{baseExec, true, false}
explainExec.analyzeExec = &mockOper
defer func() {
if panicErr := recover(); panicErr != nil && !mockOper.closed {
Expand Down

0 comments on commit d090ccc

Please sign in to comment.