wecisecode 2 weeks ago
parent
commit
02b5154e31
2 changed files with 49 additions and 44 deletions
  1. 32 28
      odbctest/odbcmql/mqls_do.go
  2. 17 16
      odbctest/odbcmql/mqls_doaction.go

+ 32 - 28
odbctest/odbcmql/mqls_do.go

@@ -225,7 +225,8 @@ func (mt *MQLTest) RunMQLTryDo(t *testing.T, ctx context.Context,
 			tn = fmt.Sprint(tn, "(retry ", retry_count, ")")
 			tn = fmt.Sprint(tn, "(retry ", retry_count, ")")
 		}
 		}
 		var seriouserror bool
 		var seriouserror bool
-		seriouserror, err = mt.RunMQLTryOnce(t, ctx,
+		report := retry_count >= retry_limit
+		seriouserror, err = mt.RunMQLTryOnce(t, report, ctx,
 			global,
 			global,
 			topvars,
 			topvars,
 			dirvars,
 			dirvars,
@@ -243,7 +244,7 @@ func (mt *MQLTest) RunMQLTryDo(t *testing.T, ctx context.Context,
 	return
 	return
 }
 }
 
 
-func (mt *MQLTest) RunMQLTryOnce(t *testing.T, ctx context.Context,
+func (mt *MQLTest) RunMQLTryOnce(t *testing.T, report bool, ctx context.Context,
 	global *GlobalVars,
 	global *GlobalVars,
 	topvars *CurrentVars,
 	topvars *CurrentVars,
 	dirvars *CurrentVars,
 	dirvars *CurrentVars,
@@ -272,7 +273,7 @@ func (mt *MQLTest) RunMQLTryOnce(t *testing.T, ctx context.Context,
 	mqlstr = strings.TrimSpace(mqlstr)
 	mqlstr = strings.TrimSpace(mqlstr)
 	if mqlstr == "" {
 	if mqlstr == "" {
 		rtn := &odb.Result{}
 		rtn := &odb.Result{}
-		seriouserror, err = mt.doFollowThroughActions(t, testname, toption, rtn, actionexprs.FollowThroughActions(), mqri.PreparedQueryString)
+		seriouserror, err = mt.doFollowThroughActions(t, report, testname, toption, rtn, actionexprs.FollowThroughActions(), mqri.PreparedQueryString)
 		if err != nil {
 		if err != nil {
 			logger.Info(fmt.Sprint("mql ", testname, " done, empty mql ignore usetime"))
 			logger.Info(fmt.Sprint("mql ", testname, " done, empty mql ignore usetime"))
 			return
 			return
@@ -286,8 +287,9 @@ func (mt *MQLTest) RunMQLTryOnce(t *testing.T, ctx context.Context,
 	if toption.regex[OnErrorPass] != nil {
 	if toption.regex[OnErrorPass] != nil {
 		if e == nil {
 		if e == nil {
 			e = merrs.NewError(fmt.Sprint("expect error ", toption.regex[OnErrorPass].String(), ", but no error occurs"))
 			e = merrs.NewError(fmt.Sprint("expect error ", toption.regex[OnErrorPass].String(), ", but no error occurs"))
-			assert.Nil(t, "error", e)
-			// 不直接输出错误信息,返回错误信息,中断循环, 在 testing.T 中报告错误,中断测试
+			if report {
+				assert.Nil(t, "error", e)
+			}
 			return false, e
 			return false, e
 		}
 		}
 		if toption.regex[OnErrorPass].MatchString(e.Error()) {
 		if toption.regex[OnErrorPass].MatchString(e.Error()) {
@@ -312,11 +314,10 @@ func (mt *MQLTest) RunMQLTryOnce(t *testing.T, ctx context.Context,
 			}
 			}
 			return false, nil
 			return false, nil
 		}
 		}
-		if !assert.Nil(t, "error", e) {
-			// 不直接输出错误信息,返回错误信息,中断循环, 在 testing.T 中报告错误,中断测试
-			return false, e
+		if report {
+			assert.Nil(t, "error", e)
 		}
 		}
-		return false, nil
+		return false, e
 	}
 	}
 
 
 	mt.scopevars.Lock()
 	mt.scopevars.Lock()
@@ -357,7 +358,7 @@ func (mt *MQLTest) RunMQLTryOnce(t *testing.T, ctx context.Context,
 	}
 	}
 	mt.scopevars.Unlock()
 	mt.scopevars.Unlock()
 
 
-	seriouserror, err = mt.doFollowThroughActions(t, testname, toption, rtn, actionexprs.FollowThroughActions(), mqlstr)
+	seriouserror, err = mt.doFollowThroughActions(t, report, testname, toption, rtn, actionexprs.FollowThroughActions(), mqlstr)
 	if err != nil {
 	if err != nil {
 		logger.Info(fmt.Sprint("mql ", testname, " done, usetime=", ut))
 		logger.Info(fmt.Sprint("mql ", testname, " done, usetime=", ut))
 		return
 		return
@@ -366,7 +367,7 @@ func (mt *MQLTest) RunMQLTryOnce(t *testing.T, ctx context.Context,
 	return
 	return
 }
 }
 
 
-func (mt *MQLTest) doFollowThroughActions(t *testing.T, testname string, toption *OnErrorOption, rtn *odb.Result, actions []*Action, mql string) (seriouserror bool, err error) {
+func (mt *MQLTest) doFollowThroughActions(t *testing.T, report bool, testname string, toption *OnErrorOption, rtn *odb.Result, actions []*Action, mql string) (seriouserror bool, err error) {
 	if len(actions) > 0 {
 	if len(actions) > 0 {
 		if rtn == nil {
 		if rtn == nil {
 			s := "返回值为空"
 			s := "返回值为空"
@@ -385,9 +386,10 @@ func (mt *MQLTest) doFollowThroughActions(t *testing.T, testname string, toption
 				err = nil
 				err = nil
 				return
 				return
 			}
 			}
-			if !assert.NotNil(t, rtn, err) {
-				return
+			if report {
+				assert.NotNil(t, rtn, err)
 			}
 			}
+			return
 		}
 		}
 		for _, act := range actions {
 		for _, act := range actions {
 			breakup := false
 			breakup := false
@@ -421,9 +423,10 @@ func (mt *MQLTest) doFollowThroughActions(t *testing.T, testname string, toption
 						err = nil
 						err = nil
 						return
 						return
 					}
 					}
-					if !assert.Nil(t, s, err) {
-						return
+					if report {
+						assert.Nil(t, s, err)
 					}
 					}
+					return
 				}
 				}
 			case "metainfo":
 			case "metainfo":
 				bs, e := json.MarshalIndent(rtn.Meta, "", "    ")
 				bs, e := json.MarshalIndent(rtn.Meta, "", "    ")
@@ -443,10 +446,10 @@ func (mt *MQLTest) doFollowThroughActions(t *testing.T, testname string, toption
 						err = nil
 						err = nil
 						return
 						return
 					}
 					}
-					if !assert.Nil(t, "error", err) {
-						// 不直接输出错误信息,返回错误信息,中断循环, 在 testing.T 中报告错误,中断测试
-						return
+					if report {
+						assert.Nil(t, "error", err)
 					}
 					}
+					return
 				}
 				}
 				logger.Info(fmt.Sprint("mql ", testname, " meta info:\n", string(bs)))
 				logger.Info(fmt.Sprint("mql ", testname, " meta info:\n", string(bs)))
 			case "output":
 			case "output":
@@ -467,10 +470,10 @@ func (mt *MQLTest) doFollowThroughActions(t *testing.T, testname string, toption
 						err = nil
 						err = nil
 						return
 						return
 					}
 					}
-					if !assert.Nil(t, "error", err) {
-						// 不直接输出错误信息,返回错误信息,中断循环, 在 testing.T 中报告错误,中断测试
-						return
+					if report {
+						assert.Nil(t, "error", err)
 					}
 					}
+					return
 				}
 				}
 				total := ""
 				total := ""
 				if len(rtn.Data) > 0 {
 				if len(rtn.Data) > 0 {
@@ -506,13 +509,13 @@ func (mt *MQLTest) doFollowThroughActions(t *testing.T, testname string, toption
 						err = nil
 						err = nil
 						return
 						return
 					}
 					}
-					if !assert.Equal(t, n, len(rtn.Data), err) {
-						// 不直接输出错误信息,返回错误信息,中断循环, 在 testing.T 中报告错误,中断测试
-						return
+					if report {
+						assert.Equal(t, n, len(rtn.Data), err)
 					}
 					}
+					return
 				}
 				}
 			case "match":
 			case "match":
-				breakup, seriouserror, err = DoActionMatch(t, args, mql, rtn, toption)
+				breakup, seriouserror, err = DoActionMatch(t, report, args, mql, rtn, toption)
 				if breakup {
 				if breakup {
 					return seriouserror, err
 					return seriouserror, err
 				}
 				}
@@ -595,14 +598,15 @@ func (mt *MQLTest) doFollowThroughActions(t *testing.T, testname string, toption
 						err = nil
 						err = nil
 						return
 						return
 					}
 					}
-					if !assert.Equal(t, n, x, err) {
-						// 不直接输出错误信息,返回错误信息,中断循环, 在 testing.T 中报告错误,中断测试
-						return
+					if report {
+						assert.Equal(t, n, x, err)
 					}
 					}
+					return
 				}
 				}
 			case "equal":
 			case "equal":
 				breakup, seriouserror, err := DoActionEqual(
 				breakup, seriouserror, err := DoActionEqual(
 					t,
 					t,
+					report,
 					toption,
 					toption,
 					rtn,
 					rtn,
 					cast.ToStringSlice(args)...)
 					cast.ToStringSlice(args)...)

+ 17 - 16
odbctest/odbcmql/mqls_doaction.go

@@ -14,7 +14,7 @@ import (
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/assert"
 )
 )
 
 
-func DoActionMatch(t *testing.T, args []any, mql string, rtn *odb.Result, toption *OnErrorOption) (breakup bool, seriouserror bool, err error) {
+func DoActionMatch(t *testing.T, report bool, args []any, mql string, rtn *odb.Result, toption *OnErrorOption) (breakup bool, seriouserror bool, err error) {
 	if len(args) < 2 {
 	if len(args) < 2 {
 		s := "match(Kn,Mn) 需要至少两个参数"
 		s := "match(Kn,Mn) 需要至少两个参数"
 		err = merrs.New("%s", s)
 		err = merrs.New("%s", s)
@@ -55,7 +55,7 @@ func DoActionMatch(t *testing.T, args []any, mql string, rtn *odb.Result, toptio
 		}
 		}
 		ms = append(ms, m)
 		ms = append(ms, m)
 	}
 	}
-	if i > len(args) {
+	if i < len(args) {
 		err = merrs.New("match(Kn,Mn) 参数 Kn,Mn 需要成对出现")
 		err = merrs.New("match(Kn,Mn) 参数 Kn,Mn 需要成对出现")
 		assert.Nil(t, "参数错误", err)
 		assert.Nil(t, "参数错误", err)
 		seriouserror = true
 		seriouserror = true
@@ -90,16 +90,16 @@ func DoActionMatch(t *testing.T, args []any, mql string, rtn *odb.Result, toptio
 			breakup = true
 			breakup = true
 			return
 			return
 		}
 		}
-		if !assert.Nil(t, "error", err) {
-			// 不直接输出错误信息,返回错误信息,中断循环, 在 testing.T 中报告错误,中断测试
-			breakup = true
-			return
+		if report {
+			assert.Nil(t, "error", err)
 		}
 		}
+		breakup = true
+		return
 	}
 	}
 	return
 	return
 }
 }
 
 
-func DoActionEqual(t *testing.T, toption *OnErrorOption, result *odb.Result, args ...string) (breakup bool, seriouserror bool, err error) {
+func DoActionEqual(t *testing.T, report bool, toption *OnErrorOption, result *odb.Result, args ...string) (breakup bool, seriouserror bool, err error) {
 	if len(args) < 3 {
 	if len(args) < 3 {
 		err = merrs.New("%s", "equal(N,F,V) 需要三个参数")
 		err = merrs.New("%s", "equal(N,F,V) 需要三个参数")
 		assert.Nil(t, "参数错误", err)
 		assert.Nil(t, "参数错误", err)
@@ -124,13 +124,13 @@ func DoActionEqual(t *testing.T, toption *OnErrorOption, result *odb.Result, arg
 		}
 		}
 		if n < 0 && result.Meta != nil {
 		if n < 0 && result.Meta != nil {
 			dat := result.Meta
 			dat := result.Meta
-			breakup, seriouserror, err = DeepEqual(t, toption, dat, field, value)
+			breakup, seriouserror, err = DeepEqual(t, report, toption, dat, field, value)
 			if breakup {
 			if breakup {
 				return
 				return
 			}
 			}
 		} else if len(result.Data) > n && result.Data[n] != nil {
 		} else if len(result.Data) > n && result.Data[n] != nil {
 			dat := result.Data[n]
 			dat := result.Data[n]
-			breakup, seriouserror, err = DeepEqual(t, toption, dat, field, value)
+			breakup, seriouserror, err = DeepEqual(t, report, toption, dat, field, value)
 			if breakup {
 			if breakup {
 				return
 				return
 			}
 			}
@@ -151,16 +151,16 @@ func DoActionEqual(t *testing.T, toption *OnErrorOption, result *odb.Result, arg
 				err = nil
 				err = nil
 				return
 				return
 			}
 			}
-			if !assert.Equal(t, value, "", err) {
-				// 不直接输出错误信息,返回错误信息,中断循环, 在 testing.T 中报告错误,中断测试
-				return
+			if report {
+				assert.Equal(t, value, "", err)
 			}
 			}
+			return
 		}
 		}
 	}
 	}
 	return
 	return
 }
 }
 
 
-func DeepEqual(t *testing.T, toption *OnErrorOption, dat map[string]any, field, value string) (breakup bool, seriouserror bool, err error) {
+func DeepEqual(t *testing.T, report bool, toption *OnErrorOption, dat map[string]any, field, value string) (breakup bool, seriouserror bool, err error) {
 	kks := strings.Split(field, ".")
 	kks := strings.Split(field, ".")
 	kki := len(kks)
 	kki := len(kks)
 	v := ""
 	v := ""
@@ -246,10 +246,11 @@ func DeepEqual(t *testing.T, toption *OnErrorOption, dat map[string]any, field,
 			err = nil
 			err = nil
 			return
 			return
 		}
 		}
-		if !assert.Equal(t, value, v, err) {
-			breakup = true
-			return
+		if report {
+			assert.Equal(t, value, v, err)
 		}
 		}
+		breakup = true
+		return
 	}
 	}
 	return
 	return
 }
 }