Skip to content

Commit

Permalink
ci: scale more timeouts in http mats
Browse files Browse the repository at this point in the history
GitHub Actions macOS test builds continue to generate spurious test
failures that waste our time. Try logging the actual time used when
we are running with scale-timeout enabled.
  • Loading branch information
owaddell-beckman committed Jan 23, 2024
1 parent cc96b0c commit d9f67c1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/swish/http.ms
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@
(let-values ([(ip op) (connect-tcp "127.0.0.1" (get-http-port))])
(put-bytevector op (string->utf8 "Malformed Request\r\n\r\n"))
(flush-output-port op)
(receive (after 10 (throw 'no-child-log))
(test:receive (after 10 (throw 'no-child-log))
[`(<child-end> [reason #(http-unhandled-input ,x)])
(assert (string=? (utf8->string x) "Malformed Request"))])
(close-port op))
Expand All @@ -792,7 +792,7 @@
(spawn&link
(lambda ()
(send me `#(read ,(utf8->string (get-bytevector-all ip)))))))
(receive (after 100 (throw 'timeout))
(test:receive (after 100 (throw 'timeout))
[#(read ,x)
(unless (string=? x
(string-append
Expand All @@ -807,7 +807,7 @@
[fail-msg `#(accept-tcp-failed "listener" "who" "errno")])
(link http)
(send http fail-msg)
(receive (after 100 (throw 'timeout))
(test:receive (after 100 (throw 'timeout))
[`(EXIT ,@http ,@fail-msg) 'ok])))

(http-mat http-respond ()
Expand Down Expand Up @@ -1058,7 +1058,7 @@
(match ls
[() 'ok]
[(,n . ,rest)
(receive (after 100 (throw `#(failed-to-read-data ,n)))
(test:receive (after 100 (throw `#(failed-to-read-data ,n)))
[#(read ,@n) (lp rest)])])))

(check-loopback '(9 8 7 6 5))
Expand Down Expand Up @@ -1387,14 +1387,14 @@
(send pid msg)
(check c s)))
(define (check-crash c s)
(receive (after 100 (throw 'no-client-close))
(test:receive (after 100 (throw 'no-client-close))
[#(ws:closed ,@c 1011 "") 'ok])
(receive (after 100 (throw 'no-child-log))
(test:receive (after 100 (throw 'no-child-log))
[`(<child-end> [pid ,@s] [reason crashed]) 'ok]))
(define (check-normal c s)
(receive (after 100 (throw 'no-client-close))
(test:receive (after 100 (throw 'no-client-close))
[#(ws:closed ,@c 1000 "") 'ok])
(receive (after 100 (throw 'no-child-log))
(test:receive (after 100 (throw 'no-child-log))
[`(<child-end> [pid ,@s] [reason normal]) 'ok]))
(do-test #f 'crash check-crash)
(do-test #t 'crash check-crash)
Expand Down
26 changes: 25 additions & 1 deletion src/swish/testing.ss
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
start-event-mgr
start-silent-event-mgr
system-mat
test:receive
)
(import
(chezscheme)
Expand Down Expand Up @@ -347,6 +348,30 @@
[stderr (receive [#(stderr ,@os-pid ,lines) lines])]
[exit-status exit-status])])))))

(define-syntax (test:receive x)
(define (en-guarde cl)
(syntax-case cl ()
[(pattern (guard g) b1 b2 ...)
(eq? (datum guard) 'guard)
cl]
[(pattern b1 b2 ...)
#'(pattern (guard #t) b1 b2 ...)]))
(syntax-case x ()
[(_ (after timeout t1 t2 ...) clause ...)
(and (eq? (datum after) 'after) (getenv "TIMEOUT_SCALE_FACTOR"))
(with-syntax ([(quote #(at offset fn)) (find-source x)]
[(n ...) (iota (length (datum (clause ...))))]
[((pattern guard b1 b2 ...) ...)
(map en-guarde #'(clause ...))])
#'(let* ([raw-timeout timeout]
[start (erlang:now)])
(define (report where)
(fprintf (console-error-port) "hit clause ~s at ~a:~s after ~s ms [raw timeout ~s]\n"
where fn offset (- (erlang:now) start) raw-timeout))
(receive (after (scale-timeout raw-timeout) (report 'timeout) t1 t2 ...)
[pattern guard (report n) b1 b2 ...] ...)))]
[(_ e ...) #'(receive e ...)]))

(define (scale-timeout timeout)
(define scale-factor
(or (cond
Expand Down Expand Up @@ -547,5 +572,4 @@
[() (getenv var)]
[(x) (when (string? x) (putenv var x))])))
...)]))

)

0 comments on commit d9f67c1

Please sign in to comment.