mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
feat: log rendezvous when running tests
This commit is contained in:
@@ -120,6 +120,10 @@ func (tc *TCase) ToTestCase() (*TestCase, error) {
|
|||||||
testCase.TestSteps = append(testCase.TestSteps, &stepTransaction{
|
testCase.TestSteps = append(testCase.TestSteps, &stepTransaction{
|
||||||
step: step,
|
step: step,
|
||||||
})
|
})
|
||||||
|
} else if step.Rendezvous != nil {
|
||||||
|
testCase.TestSteps = append(testCase.TestSteps, &stepRendezvous{
|
||||||
|
step: step,
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
log.Warn().Interface("step", step).Msg("[convertTestCase] unexpected step")
|
log.Warn().Interface("step", step).Msg("[convertTestCase] unexpected step")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ type TStep struct {
|
|||||||
Request *Request `json:"request,omitempty" yaml:"request,omitempty"`
|
Request *Request `json:"request,omitempty" yaml:"request,omitempty"`
|
||||||
TestCase *TestCase `json:"testcase,omitempty" yaml:"testcase,omitempty"`
|
TestCase *TestCase `json:"testcase,omitempty" yaml:"testcase,omitempty"`
|
||||||
Transaction *Transaction `json:"transaction,omitempty" yaml:"transaction,omitempty"`
|
Transaction *Transaction `json:"transaction,omitempty" yaml:"transaction,omitempty"`
|
||||||
|
Rendezvous *Rendezvous `json:"rendezvous,omitempty" yaml:"rendezvous,omitempty"`
|
||||||
Variables map[string]interface{} `json:"variables,omitempty" yaml:"variables,omitempty"`
|
Variables map[string]interface{} `json:"variables,omitempty" yaml:"variables,omitempty"`
|
||||||
SetupHooks []string `json:"setup_hooks,omitempty" yaml:"setup_hooks,omitempty"`
|
SetupHooks []string `json:"setup_hooks,omitempty" yaml:"setup_hooks,omitempty"`
|
||||||
TeardownHooks []string `json:"teardown_hooks,omitempty" yaml:"teardown_hooks,omitempty"`
|
TeardownHooks []string `json:"teardown_hooks,omitempty" yaml:"teardown_hooks,omitempty"`
|
||||||
@@ -63,6 +64,12 @@ type Transaction struct {
|
|||||||
Name string `json:"name" yaml:"name"`
|
Name string `json:"name" yaml:"name"`
|
||||||
Type string `json:"type" yaml:"type"` // start/end
|
Type string `json:"type" yaml:"type"` // start/end
|
||||||
}
|
}
|
||||||
|
type Rendezvous struct {
|
||||||
|
Name string `json:"name" yaml:"name"` // required
|
||||||
|
Percent float32 `json:"percent,omitempty" yaml:"percent,omitempty"` // default to 1(100%)
|
||||||
|
Number int64 `json:"number,omitempty" yaml:"number,omitempty"`
|
||||||
|
Timeout int64 `json:"timeout,omitempty" yaml:"timeout,omitempty"` // milliseconds
|
||||||
|
}
|
||||||
|
|
||||||
// TCase represents testcase data structure.
|
// TCase represents testcase data structure.
|
||||||
// Each testcase includes one public config and several sequential teststeps.
|
// Each testcase includes one public config and several sequential teststeps.
|
||||||
|
|||||||
@@ -118,14 +118,23 @@ func (r *hrpRunner) runCase(testcase *TestCase) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *hrpRunner) runStep(step IStep, config *TConfig) (stepResult *stepData, err error) {
|
func (r *hrpRunner) runStep(step IStep, config *TConfig) (stepResult *stepData, err error) {
|
||||||
// step type priority order: transaction > testcase > request
|
// step type priority order: transaction > rendezvous > testcase > request
|
||||||
if stepTransaction, ok := step.(*stepTransaction); ok {
|
if stepTran, ok := step.(*stepTransaction); ok {
|
||||||
// transaction
|
// transaction
|
||||||
log.Info().
|
log.Info().
|
||||||
Str("name", stepTransaction.step.Transaction.Name).
|
Str("name", stepTran.step.Transaction.Name).
|
||||||
Str("type", stepTransaction.step.Transaction.Type).
|
Str("type", stepTran.step.Transaction.Type).
|
||||||
Msg("transaction")
|
Msg("transaction")
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
} else if stepRend, ok := step.(*stepRendezvous); ok {
|
||||||
|
// rendezvous
|
||||||
|
log.Info().
|
||||||
|
Str("name", stepRend.step.Rendezvous.Name).
|
||||||
|
Float32("percent", stepRend.step.Rendezvous.Percent).
|
||||||
|
Int64("number", stepRend.step.Rendezvous.Number).
|
||||||
|
Int64("timeout", stepRend.step.Rendezvous.Timeout).
|
||||||
|
Msg("rendezvous")
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info().Str("step", step.Name()).Msg("run step start")
|
log.Info().Str("step", step.Name()).Msg("run step start")
|
||||||
|
|||||||
@@ -297,3 +297,23 @@ func (s *stepTransaction) Type() string {
|
|||||||
func (s *stepTransaction) ToStruct() *TStep {
|
func (s *stepTransaction) ToStruct() *TStep {
|
||||||
return s.step
|
return s.step
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// implements IStep interface
|
||||||
|
type stepRendezvous struct {
|
||||||
|
step *TStep
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepRendezvous) Name() string {
|
||||||
|
if s.step.Name != "" {
|
||||||
|
return s.step.Name
|
||||||
|
}
|
||||||
|
return s.step.Rendezvous.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepRendezvous) Type() string {
|
||||||
|
return "rendezvous"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepRendezvous) ToStruct() *TStep {
|
||||||
|
return s.step
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user