mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-15 04:19:28 +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{
|
||||
step: step,
|
||||
})
|
||||
} else if step.Rendezvous != nil {
|
||||
testCase.TestSteps = append(testCase.TestSteps, &stepRendezvous{
|
||||
step: step,
|
||||
})
|
||||
} else {
|
||||
log.Warn().Interface("step", step).Msg("[convertTestCase] unexpected step")
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ type TStep struct {
|
||||
Request *Request `json:"request,omitempty" yaml:"request,omitempty"`
|
||||
TestCase *TestCase `json:"testcase,omitempty" yaml:"testcase,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"`
|
||||
SetupHooks []string `json:"setup_hooks,omitempty" yaml:"setup_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"`
|
||||
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.
|
||||
// Each testcase includes one public config and several sequential teststeps.
|
||||
|
||||
17
runner.go
17
runner.go
@@ -118,14 +118,23 @@ func (r *hrpRunner) runCase(testcase *TestCase) error {
|
||||
}
|
||||
|
||||
func (r *hrpRunner) runStep(step IStep, config *TConfig) (stepResult *stepData, err error) {
|
||||
// step type priority order: transaction > testcase > request
|
||||
if stepTransaction, ok := step.(*stepTransaction); ok {
|
||||
// step type priority order: transaction > rendezvous > testcase > request
|
||||
if stepTran, ok := step.(*stepTransaction); ok {
|
||||
// transaction
|
||||
log.Info().
|
||||
Str("name", stepTransaction.step.Transaction.Name).
|
||||
Str("type", stepTransaction.step.Transaction.Type).
|
||||
Str("name", stepTran.step.Transaction.Name).
|
||||
Str("type", stepTran.step.Transaction.Type).
|
||||
Msg("transaction")
|
||||
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")
|
||||
|
||||
20
step.go
20
step.go
@@ -297,3 +297,23 @@ func (s *stepTransaction) Type() string {
|
||||
func (s *stepTransaction) ToStruct() *TStep {
|
||||
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