mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
change: update models
This commit is contained in:
@@ -107,7 +107,7 @@ func (b *hrpBoomer) convertBoomerTask(testcase *TestCase) *boomer.Task {
|
|||||||
for name, transaction := range runner.transactions {
|
for name, transaction := range runner.transactions {
|
||||||
if len(transaction) == 1 {
|
if len(transaction) == 1 {
|
||||||
// if transaction end time not exists, use testcase end time instead
|
// if transaction end time not exists, use testcase end time instead
|
||||||
duration := endTime.Sub(transaction[TransactionStart])
|
duration := endTime.Sub(transaction[transactionStart])
|
||||||
b.RecordTransaction(name, transactionSuccess, duration.Milliseconds(), 0)
|
b.RecordTransaction(name, transactionSuccess, duration.Milliseconds(), 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,16 +69,16 @@ const (
|
|||||||
stepTypeRendezvous stepType = "rendezvous"
|
stepTypeRendezvous stepType = "rendezvous"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TransactionType string
|
type transactionType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TransactionStart TransactionType = "start"
|
transactionStart transactionType = "start"
|
||||||
TransactionEnd TransactionType = "end"
|
transactionEnd transactionType = "end"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Transaction struct {
|
type Transaction struct {
|
||||||
Name string `json:"name" yaml:"name"`
|
Name string `json:"name" yaml:"name"`
|
||||||
Type TransactionType `json:"type" yaml:"type"`
|
Type transactionType `json:"type" yaml:"type"`
|
||||||
}
|
}
|
||||||
type Rendezvous struct {
|
type Rendezvous struct {
|
||||||
Name string `json:"name" yaml:"name"` // required
|
Name string `json:"name" yaml:"name"` // required
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func NewRunner(t *testing.T) *hrpRunner {
|
|||||||
Timeout: 30 * time.Second,
|
Timeout: 30 * time.Second,
|
||||||
},
|
},
|
||||||
sessionVariables: make(map[string]interface{}),
|
sessionVariables: make(map[string]interface{}),
|
||||||
transactions: make(map[string]map[TransactionType]time.Time),
|
transactions: make(map[string]map[transactionType]time.Time),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ type hrpRunner struct {
|
|||||||
sessionVariables map[string]interface{}
|
sessionVariables map[string]interface{}
|
||||||
// transactions stores transaction timing info.
|
// transactions stores transaction timing info.
|
||||||
// key is transaction name, value is map of transaction type and time, e.g. start time and end time.
|
// key is transaction name, value is map of transaction type and time, e.g. start time and end time.
|
||||||
transactions map[string]map[TransactionType]time.Time
|
transactions map[string]map[transactionType]time.Time
|
||||||
startTime time.Time // record start time of the testcase
|
startTime time.Time // record start time of the testcase
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ type hrpRunner struct {
|
|||||||
func (r *hrpRunner) Reset() *hrpRunner {
|
func (r *hrpRunner) Reset() *hrpRunner {
|
||||||
log.Info().Msg("[init] Reset session variables")
|
log.Info().Msg("[init] Reset session variables")
|
||||||
r.sessionVariables = make(map[string]interface{})
|
r.sessionVariables = make(map[string]interface{})
|
||||||
r.transactions = make(map[string]map[TransactionType]time.Time)
|
r.transactions = make(map[string]map[transactionType]time.Time)
|
||||||
r.startTime = time.Now()
|
r.startTime = time.Now()
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
@@ -234,25 +234,25 @@ func (r *hrpRunner) runStepTransaction(transaction *Transaction) (stepResult *st
|
|||||||
|
|
||||||
// create transaction if not exists
|
// create transaction if not exists
|
||||||
if _, ok := r.transactions[transaction.Name]; !ok {
|
if _, ok := r.transactions[transaction.Name]; !ok {
|
||||||
r.transactions[transaction.Name] = make(map[TransactionType]time.Time)
|
r.transactions[transaction.Name] = make(map[transactionType]time.Time)
|
||||||
}
|
}
|
||||||
|
|
||||||
// record transaction start time, override if already exists
|
// record transaction start time, override if already exists
|
||||||
if transaction.Type == TransactionStart {
|
if transaction.Type == transactionStart {
|
||||||
r.transactions[transaction.Name][TransactionStart] = time.Now()
|
r.transactions[transaction.Name][transactionStart] = time.Now()
|
||||||
}
|
}
|
||||||
// record transaction end time, override if already exists
|
// record transaction end time, override if already exists
|
||||||
if transaction.Type == TransactionEnd {
|
if transaction.Type == transactionEnd {
|
||||||
r.transactions[transaction.Name][TransactionEnd] = time.Now()
|
r.transactions[transaction.Name][transactionEnd] = time.Now()
|
||||||
|
|
||||||
// if transaction start time not exists, use testcase start time instead
|
// if transaction start time not exists, use testcase start time instead
|
||||||
if _, ok := r.transactions[transaction.Name][TransactionStart]; !ok {
|
if _, ok := r.transactions[transaction.Name][transactionStart]; !ok {
|
||||||
r.transactions[transaction.Name][TransactionStart] = r.startTime
|
r.transactions[transaction.Name][transactionStart] = r.startTime
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate transaction duration
|
// calculate transaction duration
|
||||||
duration := r.transactions[transaction.Name][TransactionEnd].Sub(
|
duration := r.transactions[transaction.Name][transactionEnd].Sub(
|
||||||
r.transactions[transaction.Name][TransactionStart])
|
r.transactions[transaction.Name][transactionStart])
|
||||||
stepResult.elapsed = duration.Milliseconds()
|
stepResult.elapsed = duration.Milliseconds()
|
||||||
log.Info().Str("name", transaction.Name).Dur("elapsed", duration).Msg("transaction")
|
log.Info().Str("name", transaction.Name).Dur("elapsed", duration).Msg("transaction")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ func (s *StepRequest) CallRefCase(tc *TestCase) *StepTestCaseWithOptionalArgs {
|
|||||||
func (s *StepRequest) StartTransaction(name string) *StepTransaction {
|
func (s *StepRequest) StartTransaction(name string) *StepTransaction {
|
||||||
s.step.Transaction = &Transaction{
|
s.step.Transaction = &Transaction{
|
||||||
Name: name,
|
Name: name,
|
||||||
Type: TransactionStart,
|
Type: transactionStart,
|
||||||
}
|
}
|
||||||
return &StepTransaction{
|
return &StepTransaction{
|
||||||
step: s.step,
|
step: s.step,
|
||||||
@@ -189,7 +189,7 @@ func (s *StepRequest) StartTransaction(name string) *StepTransaction {
|
|||||||
func (s *StepRequest) EndTransaction(name string) *StepTransaction {
|
func (s *StepRequest) EndTransaction(name string) *StepTransaction {
|
||||||
s.step.Transaction = &Transaction{
|
s.step.Transaction = &Transaction{
|
||||||
Name: name,
|
Name: name,
|
||||||
Type: TransactionEnd,
|
Type: transactionEnd,
|
||||||
}
|
}
|
||||||
return &StepTransaction{
|
return &StepTransaction{
|
||||||
step: s.step,
|
step: s.step,
|
||||||
|
|||||||
Reference in New Issue
Block a user