mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
refactor: SessionRunner, remove startTime
This commit is contained in:
+7
-7
@@ -424,12 +424,13 @@ func (r *CaseRunner) NewSession() *SessionRunner {
|
|||||||
type SessionRunner struct {
|
type SessionRunner struct {
|
||||||
caseRunner *CaseRunner // all session runners share one CaseRunner
|
caseRunner *CaseRunner // all session runners share one CaseRunner
|
||||||
|
|
||||||
sessionVariables map[string]interface{}
|
sessionVariables map[string]interface{} // testcase execution session variables
|
||||||
|
summary *TestCaseSummary // record test case summary
|
||||||
|
|
||||||
// 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
|
|
||||||
summary *TestCaseSummary // record test case summary
|
|
||||||
wsConnMap map[string]*websocket.Conn // save all websocket connections
|
wsConnMap map[string]*websocket.Conn // save all websocket connections
|
||||||
inheritWsConnMap map[string]*websocket.Conn // inherit all websocket connections
|
inheritWsConnMap map[string]*websocket.Conn // inherit all websocket connections
|
||||||
pongResponseChan chan string // channel used to receive pong response message
|
pongResponseChan chan string // channel used to receive pong response message
|
||||||
@@ -439,9 +440,9 @@ type SessionRunner struct {
|
|||||||
func (r *SessionRunner) resetSession() {
|
func (r *SessionRunner) resetSession() {
|
||||||
log.Info().Msg("reset session runner")
|
log.Info().Msg("reset session runner")
|
||||||
r.sessionVariables = make(map[string]interface{})
|
r.sessionVariables = make(map[string]interface{})
|
||||||
r.transactions = make(map[string]map[transactionType]time.Time)
|
|
||||||
r.startTime = time.Now()
|
|
||||||
r.summary = newSummary()
|
r.summary = newSummary()
|
||||||
|
|
||||||
|
r.transactions = make(map[string]map[transactionType]time.Time)
|
||||||
r.wsConnMap = make(map[string]*websocket.Conn)
|
r.wsConnMap = make(map[string]*websocket.Conn)
|
||||||
r.inheritWsConnMap = make(map[string]*websocket.Conn)
|
r.inheritWsConnMap = make(map[string]*websocket.Conn)
|
||||||
r.pongResponseChan = make(chan string, 1)
|
r.pongResponseChan = make(chan string, 1)
|
||||||
@@ -616,8 +617,7 @@ func (r *SessionRunner) InitWithParameters(parameters map[string]interface{}) {
|
|||||||
func (r *SessionRunner) GetSummary() (*TestCaseSummary, error) {
|
func (r *SessionRunner) GetSummary() (*TestCaseSummary, error) {
|
||||||
caseSummary := r.summary
|
caseSummary := r.summary
|
||||||
caseSummary.Name = r.caseRunner.Config.Name
|
caseSummary.Name = r.caseRunner.Config.Name
|
||||||
caseSummary.Time.StartAt = r.startTime
|
caseSummary.Time.Duration = time.Since(caseSummary.Time.StartAt).Seconds()
|
||||||
caseSummary.Time.Duration = time.Since(r.startTime).Seconds()
|
|
||||||
exportVars := make(map[string]interface{})
|
exportVars := make(map[string]interface{})
|
||||||
for _, value := range r.caseRunner.Config.Export {
|
for _, value := range r.caseRunner.Config.Export {
|
||||||
exportVars[value] = r.sessionVariables[value]
|
exportVars[value] = r.sessionVariables[value]
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ func (s *StepTransaction) Run(r *SessionRunner) (*StepResult, error) {
|
|||||||
|
|
||||||
// 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.summary.Time.StartAt
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate transaction duration
|
// calculate transaction duration
|
||||||
|
|||||||
+3
-1
@@ -196,7 +196,9 @@ func newSummary() *TestCaseSummary {
|
|||||||
return &TestCaseSummary{
|
return &TestCaseSummary{
|
||||||
Success: true,
|
Success: true,
|
||||||
Stat: &TestStepStat{},
|
Stat: &TestStepStat{},
|
||||||
Time: &TestCaseTime{},
|
Time: &TestCaseTime{
|
||||||
|
StartAt: time.Now(),
|
||||||
|
},
|
||||||
InOut: &TestCaseInOut{},
|
InOut: &TestCaseInOut{},
|
||||||
Records: []*StepResult{},
|
Records: []*StepResult{},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user