Skip to content

Testing helper: ephemeral-port fake HTTP server for backend tests (P2) #98

Description

@turinglambdaai

Found while auditing PodLens (turinglambdaai/podlens).

Problem

Every Rivet app's backend test suite needs a fake HTTP server (PodLens fakes the OpenAI ASR/chat endpoints and a podcast feed; Taskly/Fulcrum will need the same for their update/pipeline paths). Racket's racket/tcp offers no way to learn the port a listener bound — and app code ends up probing a hardcoded port range, which breaks under parallel CI or port collisions. PodLens currently does exactly that (tests/pipeline-test.rkt):

;; racket/tcp has no listener-port accessor; probe for a free port instead
(define port #f)
(for ([p (in-range 18432 18532)] #:unless port)
  (with-handlers ([exn:fail? void])
    (set! listener (tcp-listen p 16 #t "127.0.0.1"))
    (set! port p)))

Proposal

A small rivet/testing module (test-only, not embedded in the shipped app) providing something like:

(start-fake-http-server! handler) ; → (values port stop!)

where handler receives accepted ports (or a richer request/response shape). If a reliable listener-port accessor can be implemented inside Rivet (port-0 bind + extraction, or internal probing), expose that too — the point is that apps should not hand-roll port probing per project.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions