Skip to content

Commit

Permalink
tests: Fix race conditions in set-url online and offline tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ambrevar committed Feb 24, 2022
1 parent 763efa6 commit efa3b7d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 56 deletions.
43 changes: 15 additions & 28 deletions tests/renderer-offline/set-url.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@

(plan nil)

(class-star:define-class nyxt-user::test-data-profile (nyxt:data-profile)
((nyxt:name :initform "test"))
(:documentation "Test profile."))

(defmethod nyxt:expand-data-path ((profile nyxt-user::test-data-profile) (path nyxt:data-path))
"Don't persist data"
nil)

(defmacro with-prompt-buffer-test (command &body body)
(alexandria:with-gensyms (thread)
`(let ((,thread (bt:make-thread (lambda () ,command))))
Expand All @@ -25,31 +17,26 @@
;; (with-prompt-buffer-test (set-url)
;; (update-prompt-input (current-prompt-buffer) "foobar"))

(subtest "set-url"
(subtest "set offline url"
(let ((url-channel (nyxt::make-channel 1))
(url "nyxt:about"))
(setf nyxt::*headless-p* t)
(on nyxt:*after-startup-hook* ()
(let ((buffer-loaded-channel (nyxt::make-channel 1)))
(once-on nyxt:*after-startup-hook* ()
(once-on (prompt-buffer-ready-hook *browser*)
(prompt-buffer)
(prompter:all-ready-p prompt-buffer)
(nyxt:set-prompt-buffer-input url prompt-buffer)
(prompter:all-ready-p prompt-buffer)
(once-on (buffer-loaded-hook (current-buffer)) buffer
(calispel:! buffer-loaded-channel t))
(let ((thread (run-thread "run set-url"
(calispel:? buffer-loaded-channel 10)
(nyxt:set-url))))
(declare (ignorable thread))
(on (prompt-buffer-ready-hook *browser*)
(prompt-buffer)
(prompter:all-ready-p prompt-buffer)
(nyxt:set-prompt-buffer-input url prompt-buffer)
(prompter:all-ready-p prompt-buffer)
(nyxt/prompt-buffer-mode:return-selection prompt-buffer)
(once-on (buffer-loaded-hook (current-buffer)) buffer
(calispel:! url-channel (nyxt:render-url (nyxt:url buffer)))))
;; (bt:join-thread thread) ; TODO: Make sure thread always returns.
)))
(calispel:! url-channel (nyxt:render-url (nyxt:url buffer))))
(nyxt/prompt-buffer-mode:return-selection prompt-buffer))
(run-thread "run set-url"
;; TODO: Test if thread returns.
(nyxt:set-url)))
(nyxt:start :no-init t :no-auto-config t
:socket "/tmp/nyxt-test.socket"
:data-profile "test")
(prove:is (calispel:? url-channel 10) url)))
:profile "test")
(prove:is (calispel:? url-channel 5) url)
(quit)))

(finalize)
43 changes: 15 additions & 28 deletions tests/renderer-online/set-url.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@

(plan nil)

(class-star:define-class nyxt-user::test-data-profile (nyxt:data-profile)
((nyxt:name :initform "test"))
(:documentation "Test profile."))

(defmethod nyxt:expand-data-path ((profile nyxt-user::test-data-profile) (path nyxt:data-path))
"Don't persist data"
nil)

(defmacro with-prompt-buffer-test (command &body body)
(alexandria:with-gensyms (thread)
`(let ((,thread (bt:make-thread (lambda () ,command))))
Expand All @@ -25,31 +17,26 @@
;; (with-prompt-buffer-test (set-url)
;; (update-prompt-input (current-prompt-buffer) "foobar"))

(subtest "set-url"
(subtest "set online URL"
(let ((url-channel (nyxt::make-channel 1))
(url "http://example.org/"))
(setf nyxt::*headless-p* t)
(on nyxt:*after-startup-hook* ()
(let ((buffer-loaded-channel (nyxt::make-channel 1)))
(once-on nyxt:*after-startup-hook* ()
(once-on (prompt-buffer-ready-hook *browser*)
(prompt-buffer)
(prompter:all-ready-p prompt-buffer)
(nyxt:set-prompt-buffer-input url prompt-buffer)
(prompter:all-ready-p prompt-buffer)
(once-on (buffer-loaded-hook (current-buffer)) buffer
(calispel:! buffer-loaded-channel t))
(let ((thread (run-thread "run set-url"
(calispel:? buffer-loaded-channel 10)
(nyxt:set-url))))
(declare (ignorable thread))
(on (prompt-buffer-ready-hook *browser*)
(prompt-buffer)
(prompter:all-ready-p prompt-buffer)
(nyxt:set-prompt-buffer-input url prompt-buffer)
(prompter:all-ready-p prompt-buffer)
(nyxt/prompt-buffer-mode:return-selection prompt-buffer)
(once-on (buffer-loaded-hook (current-buffer)) buffer
(calispel:! url-channel (nyxt:render-url (nyxt:url buffer)))))
;; (bt:join-thread thread) ; TODO: Make sure thread always returns.
)))
(calispel:! url-channel (nyxt:render-url (nyxt:url buffer))))
(nyxt/prompt-buffer-mode:return-selection prompt-buffer))
(run-thread "run set-url"
;; TODO: Test if thread returns.
(nyxt:set-url)))
(nyxt:start :no-init t :no-auto-config t
:socket "/tmp/nyxt-test.socket"
:data-profile "test")
(prove:is (calispel:? url-channel 10) url)))
:profile "test")
(prove:is (calispel:? url-channel 5) url)
(quit)))

(finalize)
13 changes: 13 additions & 0 deletions tests/renderer-package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,18 @@
(uiop:define-package nyxt/tests/renderer
(:use #:common-lisp)
(:use #:nyxt)
(:shadowing-import-from #:prove #:*debug-on-error*)
(:use #:prove)
(:import-from #:class-star #:define-class))

(class-star:define-class nyxt-user::test-profile (nyxt:nyxt-profile)
((nfiles:name :initform "test"))
(:documentation "Test profile."))

(defmethod nfiles:write-file ((profile nyxt-user::test-profile) (file nfiles:file) &key)
"Don't persist test data."
nil)

(defmethod nfiles:resolve ((profile nyxt-user::test-profile) (file nyxt:history-file))
"Don't use any history."
#p"")

0 comments on commit efa3b7d

Please sign in to comment.