Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-httpclient

Named HTTP clients for Pudu: a client factory, delegating handlers, pooled keep-alive connections, handler lifetimes, logging, and resilience

0.1.1Apache-2.01

InstallClose

PersistenceTest.pudu

Pudu32 lines2.3 KB

GitHub ↗
1/** @Test.Domain.Persistence.Suite — which connections stay open and which pooled ones are reused */2module PuduLangHttpClient.Domain.PersistenceTest34import Std.Http.Message as Message5import Std.Io as Io6import Std.Test as Test7import PuduLangHttpClient.Constants.Defaults as Defaults8import PuduLangHttpClient.Domain.Persistence as Persistence910/// Runs the suite.11fn main() -> Int {12  let limits = Persistence.Limits{lifetime: 100, idleTimeout: 10}13  let idle = Persistence.Idle{link: "a", created: 0, lastUsed: 50}14  let checks = Test.suite("Domain.Persistence", &[15      Test.that("an HTTP/1.1 exchange framed by length or chunks keeps its connection", Persistence.keepsAlive("HTTP/1.1", &[], &[], &Message.Length(3)) && Persistence.keepsAlive("HTTP/1.1", &[], &[], &Message.Chunked) && Persistence.keepsAlive("HTTP/1.1", &[], &[], &Message.HeadOnly)),16      Test.not("a body ending with the connection does not", Persistence.keepsAlive("HTTP/1.1", &[], &[], &Message.UntilClose)),17      Test.not("either side asking to close does not", Persistence.keepsAlive("HTTP/1.1", &[("Connection", "close")], &[], &Message.Length(0)) || Persistence.keepsAlive("HTTP/1.1", &[], &[("connection", "upgrade, Close")], &Message.Length(0))),18      Test.not("an HTTP/1.0 response that does not ask to stay does not", Persistence.keepsAlive("HTTP/1.0", &[], &[], &Message.Length(0))),19      Test.that("an HTTP/1.0 response asking to stay does", Persistence.keepsAlive("HTTP/1.0", &[], &[("connection", "Keep-Alive")], &Message.Length(0))),20      Test.that("a connection inside both limits is usable", Persistence.usable(&idle, &limits, 59)),21      Test.not("a connection idle for its timeout is not", Persistence.usable(&idle, &limits, 60)),22      Test.not("a connection at the end of its lifetime is not", Persistence.usable(&Persistence.Idle{..idle, lastUsed: 95}, &limits, 100)),23      Test.that("infinite limits keep a connection usable", Persistence.usable(&idle, &Persistence.Limits{lifetime: Defaults.INFINITE, idleTimeout: Defaults.INFINITE}, Defaults.UNLIMITED)),24      Test.equals("a sweep splits the usable from the expired", &Persistence.sweep(&[idle, Persistence.Idle{..idle, link: "b", lastUsed: 55}], &limits, 62), &([Persistence.Idle{..idle, link: "b", lastUsed: 55}], [idle]))25    ])26  let ran = Test.run(&checks)27  for failure in Test.failuresOf(&ran) {28    let _reported = Io.writeErrorLine(failure)29  }30  Test.report(&ran)31}32