mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-19 19:39:31 +08:00
fix: fast fail , not closing the websocket connection
This commit is contained in:
@@ -361,6 +361,10 @@ func (b *HRPBoomer) convertBoomerTask(testcase *TestCase, rendezvousList []*Rend
|
||||
}
|
||||
mutex.Unlock()
|
||||
|
||||
defer func() {
|
||||
sessionRunner.releaseResources()
|
||||
}()
|
||||
|
||||
startTime := time.Now()
|
||||
for _, step := range testcase.TestSteps {
|
||||
// TODO: parse step struct
|
||||
|
||||
@@ -488,6 +488,11 @@ func (r *SessionRunner) Start(givenVars map[string]interface{}) error {
|
||||
// update config variables with given variables
|
||||
r.InitWithParameters(givenVars)
|
||||
|
||||
defer func() {
|
||||
// close session resource after all steps done or fast fail
|
||||
r.releaseResources()
|
||||
}()
|
||||
|
||||
// run step in sequential order
|
||||
for _, step := range r.caseRunner.testCase.TestSteps {
|
||||
// TODO: parse step struct
|
||||
@@ -563,19 +568,6 @@ func (r *SessionRunner) Start(givenVars map[string]interface{}) error {
|
||||
}
|
||||
}
|
||||
|
||||
// close websocket connection after all steps done
|
||||
defer func() {
|
||||
for _, wsConn := range r.wsConnMap {
|
||||
if wsConn != nil {
|
||||
log.Info().Str("testcase", config.Name).Msg("websocket disconnected")
|
||||
err := wsConn.Close()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("websocket disconnection failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
log.Info().Str("testcase", config.Name).Msg("run testcase end")
|
||||
return nil
|
||||
}
|
||||
@@ -646,3 +638,17 @@ func (r *SessionRunner) GetSummary() (*TestCaseSummary, error) {
|
||||
|
||||
return caseSummary, nil
|
||||
}
|
||||
|
||||
// releaseResources releases resources used by session runner
|
||||
func (r *SessionRunner) releaseResources() {
|
||||
// close websocket connections
|
||||
for _, wsConn := range r.wsConnMap {
|
||||
if wsConn != nil {
|
||||
log.Info().Str("testcase", r.caseRunner.testCase.Config.Name).Msg("websocket disconnected")
|
||||
err := wsConn.Close()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("websocket disconnection failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user