Commit 42aea28f authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

kernels: Make "kernel_info_request" test more robust.

* tests/kernels.scm ("kernel_info_request"): Rewrite to remove assumptions
about ordering, and to account for all the replies.
parent 4c8895dd
......@@ -59,31 +59,39 @@
(let ((request (message (header "kernel_info_request" "luser" "12345")
"{}")))
(send-message %kernel request)
(let* ((reply1 (read-message %kernel))
(reply2 (read-message %kernel))
(reply3 (read-message %kernel))
(replies (pk 'replies (list reply1 reply2 reply3))))
(and (every message? replies)
(string=? "status" (message-type reply1))
(string=? "busy"
(assoc-ref (json-string->scm (message-content reply1))
"execution_state"))
(equal? (message-parent-header reply1) (message-header request))
(let* ((replies (unfold (cut > <> 2)
(lambda (_)
(read-message %kernel 10000))
1+ 0)))
(define (type-predicate type)
(lambda (message)
(string=? (message-type message) type)))
(string=? "kernel_info_reply" (message-type reply2))
(equal? (message-parent-header reply2) (message-header request))
(and (every message? (pk 'replies replies))
(string=? "status" (message-type reply3))
(match (filter (type-predicate "status") replies)
((busy idle)
;; We got two message: busy *then* idle.
(and (string=? "busy"
(assoc-ref (json-string->scm
(message-content busy))
"execution_state"))
(string=? "idle"
(assoc-ref (json-string->scm (message-content reply3))
(assoc-ref (json-string->scm
(message-content idle))
"execution_state"))
(equal? (message-parent-header reply3) (message-header request))
(equal? (message-parent-header busy)
(message-header request))
(equal? (message-parent-header idle)
(message-header request)))))
(assoc-ref (assoc-ref
(json-string->scm (message-content reply2))
"language_info")
"name")))))
(let ((reply (find (type-predicate "kernel_info_reply")
replies)))
(and (equal? (message-parent-header reply)
(message-header request))
(let* ((content (json-string->scm (message-content reply)))
(language (assoc-ref content "language_info")))
(assoc-ref language "name"))))))))
(unless %kernel (test-skip 1))
(test-equal "execute_request"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment