handleErrorChannel handles errors while ensuring that stuck queries do not cause an infinite loop via a timeout.
(t *testing.T, isSend bool)
| 7694 | |
| 7695 | // handleErrorChannel handles errors while ensuring that stuck queries do not cause an infinite loop via a timeout. |
| 7696 | func (c *RawWireConnection) handleErrorChannel(t *testing.T, isSend bool) error { |
| 7697 | var err error |
| 7698 | select { |
| 7699 | case err = <-c.errChan: |
| 7700 | case <-time.After(c.timeout): |
| 7701 | if isSend { |
| 7702 | err = errors.New("timeout during Send") |
| 7703 | } else { |
| 7704 | err = errors.New("timeout during Receive") |
| 7705 | } |
| 7706 | } |
| 7707 | // On error, we must create a new connection since we cut the old one |
| 7708 | if err != nil { |
| 7709 | _ = c.connection.Close() |
| 7710 | connection, nErr := (&net.Dialer{}).Dial("tcp", c.network) |
| 7711 | if nErr != nil { |
| 7712 | panic(fmt.Errorf("Unable to create a new connection:\n%s\n\nOriginal error:\n%s", nErr.Error(), err.Error())) |
| 7713 | } |
| 7714 | c.connection = connection |
| 7715 | c.frontend = pgproto3.NewFrontend(connection, connection) |
| 7716 | c.init(t) |
| 7717 | } |
| 7718 | return err |
| 7719 | } |
| 7720 | |
| 7721 | // RunWireScripts runs the given collection of scripts. |
| 7722 | func RunWireScripts(t *testing.T, scripts []WireScriptTest) { |