MCPcopy
hub / github.com/httprunner/httprunner / readMessageWithTimeout

Function readMessageWithTimeout

hrp/step_websocket.go:506–534  ·  view source on GitHub ↗
(urlString string, r *SessionRunner, step *TStep)

Source from the content-addressed store, hash-verified

504}
505
506func readMessageWithTimeout(urlString string, r *SessionRunner, step *TStep) (*wsReadRespObject, error) {
507 wsConn := r.getWsClient(urlString)
508 if wsConn == nil {
509 return nil, errors.New("try to use existing connection, but there is no connection")
510 }
511 readResponseChan := make(chan *wsReadRespObject)
512 errorChan := make(chan error)
513 go func() {
514 messageType, message, err := wsConn.ReadMessage()
515 if err != nil {
516 errorChan <- err
517 } else {
518 readResponseChan <- &wsReadRespObject{
519 messageType: messageType,
520 Message: message,
521 }
522 }
523 }()
524 timer := time.NewTimer(time.Duration(step.WebSocket.GetTimeout()) * time.Millisecond)
525 select {
526 case <-timer.C:
527 timer.Stop()
528 return nil, errors.New("read timeout")
529 case err := <-errorChan:
530 return nil, err
531 case readResult := <-readResponseChan:
532 return readResult, nil
533 }
534}
535
536func writeWebSocket(urlString string, r *SessionRunner, step *TStep, stepVariables map[string]interface{}) error {
537 wsConn := r.getWsClient(urlString)

Callers 1

runStepWebSocketFunction · 0.85

Calls 3

getWsClientMethod · 0.80
GetTimeoutMethod · 0.80
StopMethod · 0.65

Tested by

no test coverage detected