summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorF. Jason Park <jp@neverwas.me>2023-03-08 06:14:36 -0800
committerF. Jason Park <jp@neverwas.me>2023-04-08 14:23:50 -0700
commit03eddc99242bb430a82f468251ed76602d457702 (patch)
tree3df1c7be54fdaa50905c783eecea5019128debf6 /test
parent4da7d24988ae096d757021eb8ed9d014990de16e (diff)
downloademacs-03eddc99242bb430a82f468251ed76602d457702.tar.gz
Add probing erc-server-reconnect-function variant
* lisp/erc/erc-backend.el (erc-server-reconnect-timeout): Replace questionable claim with recommendation for alternate value when experiencing nick rejections. (erc-server-reconnect-function): Add new, somewhat experimental value `erc-server-delayed-check-reconnect'. (erc--server-connect-function): Add variable for process-dialing monitor, a function. (erc--server-propagate-failed-connection): Add function to serve as default monitor to run on process creation and maybe execute failure handlers. (erc-server-connect): Run `erc--server-connect-function' for async processes one second after creation. (erc--server-reconnect-timeout, erc--server-reconnect-timeout-check, erc--server-reconnect-timeout-scale-function, erc--server-reconnect-timeout-double): Add supporting variables and functions for `erc-server-delayed-check-reconnect'. (erc-server-delayed-check-reconnect): Add possible alternate value for option `erc-server-reconnect-function' that only attempts to reconnect after hearing back from the server. (erc-schedule-reconnect): Ensure previous `erc-server-process' is deleted. * test/lisp/erc/erc-scenarios-base-auto-recon.el: New file. * test/lisp/erc/resources/base/reconnect/just-eof.eld: New file. * test/lisp/erc/resources/base/reconnect/just-ping.eld: New file. * test/lisp/erc/resources/base/reconnect/ping-pong.eld: New file. * test/lisp/erc/resources/base/reconnect/unexpected-disconnect.eld: New file. * test/lisp/erc/resources/erc-scenarios-common.el (erc-scenarios-common--make-bindings): Shadow `timer-list'. (Bug#62044.)
Diffstat (limited to 'test')
-rw-r--r--test/lisp/erc/erc-scenarios-base-auto-recon.el141
-rw-r--r--test/lisp/erc/resources/base/reconnect/just-eof.eld3
-rw-r--r--test/lisp/erc/resources/base/reconnect/just-ping.eld4
-rw-r--r--test/lisp/erc/resources/base/reconnect/ping-pong.eld6
-rw-r--r--test/lisp/erc/resources/base/reconnect/unexpected-disconnect.eld24
-rw-r--r--test/lisp/erc/resources/erc-scenarios-common.el1
6 files changed, 179 insertions, 0 deletions
diff --git a/test/lisp/erc/erc-scenarios-base-auto-recon.el b/test/lisp/erc/erc-scenarios-base-auto-recon.el
new file mode 100644
index 00000000000..40e2c23408b
--- /dev/null
+++ b/test/lisp/erc/erc-scenarios-base-auto-recon.el
@@ -0,0 +1,141 @@
+;;; erc-scenarios-base-auto-recon.el --- auto-recon scenarios -*- lexical-binding: t -*-
+
+;; Copyright (C) 2023 Free Software Foundation, Inc.
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'ert-x)
+(eval-and-compile
+ (let ((load-path (cons (ert-resource-directory) load-path)))
+ (require 'erc-scenarios-common)))
+
+(defun erc-scenarios-base-auto-recon--get-unused-port ()
+ (let ((server (make-network-process :name "*erc-scenarios-base-auto-recon*"
+ :host "localhost"
+ :service t
+ :server t)))
+ (delete-process server)
+ (process-contact server :service)))
+
+;; This demos one possible flavor of intermittent service.
+;; It may end up needing to be marked :unstable.
+
+(ert-deftest erc-scenarios-base-auto-recon-unavailable ()
+ :tags '(:expensive-test)
+ (erc-scenarios-common-with-cleanup
+ ((erc-server-flood-penalty 0.1)
+ (port (erc-scenarios-base-auto-recon--get-unused-port))
+ (erc--server-reconnect-timeout-scale-function (lambda (_) 1))
+ (erc-server-auto-reconnect t)
+ (erc-server-reconnect-function #'erc-server-delayed-check-reconnect)
+ (expect (erc-d-t-make-expecter))
+ (erc-scenarios-common-dialog "base/reconnect")
+ (dumb-server nil))
+
+ (ert-info ("Dialing fails: nobody home")
+ (with-current-buffer (erc :server "127.0.0.1"
+ :port port
+ :nick "tester"
+ :full-name "tester")
+ (erc-d-t-wait-for 10 (not (erc-server-process-alive)))
+ (erc-d-t-wait-for 10 erc--server-reconnect-timer)
+ (funcall expect 10 "Opening connection")
+ (funcall expect 10 "failed")
+
+ (ert-info ("Reconnect function freezes attempts at 1")
+ (funcall expect 10 '(: "reconnecting" (+ nonl) "attempt 1/2"))
+ (funcall expect 10 "nobody home")
+ (funcall expect 10 '(: "reconnecting" (+ nonl) "attempt 1/2"))
+ (funcall expect 10 "nobody home"))))
+
+ (ert-info ("Service appears")
+ (setq dumb-server (erc-d-run "localhost" port
+ 'just-eof 'unexpected-disconnect))
+ (with-current-buffer (format "127.0.0.1:%d" port)
+ (funcall expect 10 "server is in debug mode")
+ (should (equal (buffer-name) "FooNet"))))
+
+ (ert-info ("Service interrupted, reconnect starts again")
+ (with-current-buffer "FooNet"
+ (funcall expect 10 "failed")
+ (funcall expect 10 '(: "reconnecting" (+ nonl) "attempt 1/2"))))
+
+ (ert-info ("Service restored")
+ (delete-process dumb-server)
+ (setq dumb-server (erc-d-run "localhost" port
+ 'just-eof 'unexpected-disconnect))
+ (with-current-buffer "FooNet"
+ (funcall expect 10 "server is in debug mode")))
+
+ (ert-info ("Service interrupted a third time, reconnect starts yet again")
+ (with-current-buffer "FooNet"
+ (funcall expect 10 "failed")
+ (funcall expect 10 '(: "reconnecting" (+ nonl) "attempt 1/2"))
+ (erc-cmd-RECONNECT "cancel")
+ (funcall expect 10 "canceled")))))
+
+;; In this test, a listener accepts but doesn't respond to any messages.
+
+(ert-deftest erc-scenarios-base-auto-recon-no-proto ()
+ :tags '(:expensive-test)
+ (erc-scenarios-common-with-cleanup
+ ((erc-server-flood-penalty 0.1)
+ (erc-scenarios-common-dialog "base/reconnect")
+ (erc-d-auto-pong nil)
+ (dumb-server (erc-d-run "localhost" t 'unexpected-disconnect))
+ (port (process-contact dumb-server :service))
+ (erc--server-reconnect-timeout-scale-function (lambda (_) 1))
+ (erc--server-reconnect-timeout-check 0.5)
+ (erc-server-auto-reconnect t)
+ (erc-server-reconnect-function #'erc-server-delayed-check-reconnect)
+ (expect (erc-d-t-make-expecter)))
+
+ (ert-info ("Session succeeds but cut short")
+ (with-current-buffer (erc :server "127.0.0.1"
+ :port port
+ :nick "tester"
+ :full-name "tester")
+ (funcall expect 10 "server is in debug mode")
+ (should (equal (buffer-name) "FooNet"))
+ (erc-d-t-wait-for 10 erc--server-reconnect-timer)
+ (delete-process dumb-server)
+ (funcall expect 10 "failed")
+
+ (ert-info ("Reconnect function freezes attempts at 1")
+ (funcall expect 10 '(: "reconnecting" (+ nonl) "attempt 1/2"))
+ (funcall expect 10 "nobody home")
+ (funcall expect 10 "timed out while dialing")
+ (funcall expect 10 '(: "reconnecting" (+ nonl) "attempt 1/2"))
+ (funcall expect 10 "nobody home"))))
+
+ (ert-info ("Service restored")
+ (setq dumb-server (erc-d-run "localhost" port
+ 'just-ping
+ 'ping-pong
+ 'unexpected-disconnect))
+ (with-current-buffer "FooNet"
+ (funcall expect 30 "server is in debug mode")))
+
+ (ert-info ("Service interrupted again, reconnect starts again")
+ (with-current-buffer "FooNet"
+ (funcall expect 10 "failed")
+ (funcall expect 10 '(: "reconnecting" (+ nonl) "attempt 1/2"))
+ (erc-cmd-RECONNECT "cancel")
+ (funcall expect 10 "canceled")))))
+
+;;; erc-scenarios-base-auto-recon.el ends here
diff --git a/test/lisp/erc/resources/base/reconnect/just-eof.eld b/test/lisp/erc/resources/base/reconnect/just-eof.eld
new file mode 100644
index 00000000000..c80a39b3170
--- /dev/null
+++ b/test/lisp/erc/resources/base/reconnect/just-eof.eld
@@ -0,0 +1,3 @@
+;; -*- mode: lisp-data; -*-
+((eof 5 EOF))
+((drop 0 DROP))
diff --git a/test/lisp/erc/resources/base/reconnect/just-ping.eld b/test/lisp/erc/resources/base/reconnect/just-ping.eld
new file mode 100644
index 00000000000..d57888b42d3
--- /dev/null
+++ b/test/lisp/erc/resources/base/reconnect/just-ping.eld
@@ -0,0 +1,4 @@
+;; -*- mode: lisp-data; -*-
+((ping 20 "PING"))
+
+((eof 10 EOF))
diff --git a/test/lisp/erc/resources/base/reconnect/ping-pong.eld b/test/lisp/erc/resources/base/reconnect/ping-pong.eld
new file mode 100644
index 00000000000..b3d36cf6cec
--- /dev/null
+++ b/test/lisp/erc/resources/base/reconnect/ping-pong.eld
@@ -0,0 +1,6 @@
+;; -*- mode: lisp-data; -*-
+((ping 10 "PING ")
+ (0 "PONG fake"))
+
+((eof 10 EOF))
+((drop 0 DROP))
diff --git a/test/lisp/erc/resources/base/reconnect/unexpected-disconnect.eld b/test/lisp/erc/resources/base/reconnect/unexpected-disconnect.eld
new file mode 100644
index 00000000000..386d0f4b085
--- /dev/null
+++ b/test/lisp/erc/resources/base/reconnect/unexpected-disconnect.eld
@@ -0,0 +1,24 @@
+;; -*- mode: lisp-data; -*-
+((nick 10 "NICK tester"))
+((user 10 "USER user 0 * :tester")
+ (0 ":irc.foonet.org 001 tester :Welcome to the foonet IRC Network tester")
+ (0 ":irc.foonet.org 002 tester :Your host is irc.foonet.org, running version oragono-2.6.0-7481bf0385b95b16")
+ (0 ":irc.foonet.org 003 tester :This server was created Tue, 04 May 2021 05:06:18 UTC")
+ (0 ":irc.foonet.org 004 tester irc.foonet.org oragono-2.6.0-7481bf0385b95b16 BERTZios CEIMRUabefhiklmnoqstuv Iabefhkloqv")
+ (0 ":irc.foonet.org 005 tester AWAYLEN=390 BOT=B CASEMAPPING=ascii CHANLIMIT=#:100 CHANMODES=Ibe,k,fl,CEMRUimnstu CHANNELLEN=64 CHANTYPES=# ELIST=U EXCEPTS EXTBAN=,m FORWARD=f INVEX KICKLEN=390 :are supported by this server")
+ (0 ":irc.foonet.org 005 tester MAXLIST=beI:60 MAXTARGETS=4 MODES MONITOR=100 NETWORK=FooNet NICKLEN=32 PREFIX=(qaohv)~&@%+ STATUSMSG=~&@%+ TARGMAX=NAMES:1,LIST:1,KICK:1,WHOIS:1,USERHOST:10,PRIVMSG:4,TAGMSG:4,NOTICE:4,MONITOR:100 TOPICLEN=390 UTF8MAPPING=rfc8265 UTF8ONLY WHOX :are supported by this server")
+ (0 ":irc.foonet.org 005 tester draft/CHATHISTORY=100 :are supported by this server")
+ (0 ":irc.foonet.org 251 tester :There are 0 users and 3 invisible on 1 server(s)")
+ (0 ":irc.foonet.org 252 tester 0 :IRC Operators online")
+ (0 ":irc.foonet.org 253 tester 0 :unregistered connections")
+ (0 ":irc.foonet.org 254 tester 1 :channels formed")
+ (0 ":irc.foonet.org 255 tester :I have 3 clients and 0 servers")
+ (0 ":irc.foonet.org 265 tester 3 3 :Current local users 3, max 3")
+ (0 ":irc.foonet.org 266 tester 3 3 :Current global users 3, max 3")
+ (0 ":irc.foonet.org 422 tester :MOTD File is missing"))
+
+((mode-user 10 "MODE tester +i")
+ (0 ":irc.foonet.org 221 tester +i")
+ (0 ":irc.foonet.org NOTICE tester :This server is in debug mode and is logging all user I/O. If you do not wish for everything you send to be readable by the server owner(s), please disconnect."))
+
+((drop 0 DROP))
diff --git a/test/lisp/erc/resources/erc-scenarios-common.el b/test/lisp/erc/resources/erc-scenarios-common.el
index 0d9a79ae9ce..f259c88594b 100644
--- a/test/lisp/erc/resources/erc-scenarios-common.el
+++ b/test/lisp/erc/resources/erc-scenarios-common.el
@@ -121,6 +121,7 @@
(erc-modules (copy-sequence erc-modules))
(inhibit-interaction t)
(auth-source-do-cache nil)
+ (timer-list (copy-sequence timer-list))
(erc-auth-source-parameters-join-function nil)
(erc-autojoin-channels-alist nil)
(erc-server-auto-reconnect nil)