unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob 719cf4e3b5d0d334d2563a934810a6b3adc52c11 6039 bytes (raw)
name: test/lisp/erc/erc-scenarios-base-auto-recon.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
 
;;; 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

debug log:

solving 719cf4e3b5d ...
found 719cf4e3b5d in https://yhetil.org/emacs-bugs/87v8j715om.fsf__46115.3383411997$1678560809$gmane$org@neverwas.me/

applying [1/1] https://yhetil.org/emacs-bugs/87v8j715om.fsf__46115.3383411997$1678560809$gmane$org@neverwas.me/
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..719cf4e3b5d

Checking patch test/lisp/erc/erc-scenarios-base-auto-recon.el...
Applied patch test/lisp/erc/erc-scenarios-base-auto-recon.el cleanly.

skipping https://yhetil.org/emacs-bugs/87v8j715om.fsf__46115.3383411997$1678560809$gmane$org@neverwas.me/ for 719cf4e3b5d
index at:
100644 719cf4e3b5d0d334d2563a934810a6b3adc52c11	test/lisp/erc/erc-scenarios-base-auto-recon.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).