refactor: SessionRunner, remove startTime

This commit is contained in:
lilong.129
2024-08-20 14:36:51 +08:00
parent 6f0aba87be
commit 9b45b05edd
3 changed files with 12 additions and 10 deletions
+8 -8
View File
@@ -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]
+1 -1
View File
@@ -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
View File
@@ -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{},
} }