Lounge: use buffered mode, restore https connection
This commit is contained in:
1 parent
b7fb8614b7
commit
99fdd31c36
22 files changed
+956
-1269
No files matched your search
@@ -122,6 +122,26 @@ namespace Tests
|
||||
return invalid
|
||||
end function
|
||||
|
||||
' Waits on the loop's own port, shared with the fetch, the way a task loop does: each wait capped by MaxWaitMs,
|
||||
' every message handed to Handle, until it returns the response or limitMs passed.
|
||||
function RunSharedLoop(loop as object, pending as object, limitMs as integer) as dynamic
|
||||
timer = CreateObject("roTimespan")
|
||||
while timer.TotalMilliseconds() < limitMs
|
||||
message = wait(pending.MaxWaitMs(), loop.port)
|
||||
if type(message) = "roSGNodeEvent" and message.GetField() = "ping"
|
||||
loop.pings += 1
|
||||
end if
|
||||
response = pending.Handle(message)
|
||||
if response <> invalid
|
||||
return response
|
||||
end if
|
||||
if loop.pingEveryMessage
|
||||
loop.node.ping = loop.pings + 1
|
||||
end if
|
||||
end while
|
||||
return invalid
|
||||
end function
|
||||
|
||||
function CacheFilePath(request as HttpClient.Request) as string
|
||||
return HttpCache.GetFilePath(request.GetFullUrl(), request.GetHeaders(), request._saveBodyToFilePath)
|
||||
end function
|
||||
@@ -762,6 +782,8 @@ namespace Tests
|
||||
cancellation.node.cancel = true
|
||||
pending.Await()
|
||||
HttpClient.Get(m.ServerUrl("/status/200")).Cancellation(cancellation).Await()
|
||||
loop = m.CreateLoop()
|
||||
m.RunSharedLoop(loop, HttpClient.Get(m.ServerUrl("/status/200")).NoCache().Cancellation(m.CreateCancellation()).SendOn(loop.port), 3000)
|
||||
m.assertEqual(RunGarbageCollector().orphaned, 0)
|
||||
end function
|
||||
|
||||
@@ -864,6 +886,114 @@ namespace Tests
|
||||
m.assertTrue(loop.pings > 1)
|
||||
end function
|
||||
|
||||
@describe("HttpClient.PendingResponse on a task loop's port (SendOn)")
|
||||
|
||||
@it("wakes the loop as soon as the response is in, its own messages left to it")
|
||||
function _()
|
||||
loop = m.CreateLoop()
|
||||
timer = CreateObject("roTimespan")
|
||||
pending = HttpClient.Get(m.ServerUrl("/delay/200")).SendOn(loop.port)
|
||||
loop.node.ping = 1
|
||||
response = m.RunSharedLoop(loop, pending, 3000)
|
||||
m.assertEqual(response.StatusCode(), 200)
|
||||
m.AssertTook(timer, 200, 300)
|
||||
m.assertEqual(loop.pings, 1)
|
||||
end function
|
||||
|
||||
@it("times out at the deadline, its port idle or busy with the loop's messages")
|
||||
function _()
|
||||
for each busy in [false, true]
|
||||
loop = m.CreateLoop()
|
||||
loop.pingEveryMessage = busy
|
||||
timer = CreateObject("roTimespan")
|
||||
pending = HttpClient.Get(m.ServerUrl("/delay/2000")).AttemptTimeoutMs(300).SendOn(loop.port)
|
||||
loop.node.ping = 1
|
||||
response = m.RunSharedLoop(loop, pending, 3000)
|
||||
m.AssertTook(timer, 300, 400)
|
||||
m.assertTrue(response.IsTimedOut())
|
||||
end for
|
||||
end function
|
||||
|
||||
@it("sends a retry when it is due")
|
||||
function _()
|
||||
loop = m.CreateLoop()
|
||||
timer = CreateObject("roTimespan")
|
||||
pending = HttpClient.Get(m.ServerUrl("/seq/sharedretry/503,200")).RetryCount(1).RetryDelayMs(300).SendOn(loop.port)
|
||||
response = m.RunSharedLoop(loop, pending, 3000)
|
||||
m.assertEqual(response.StatusCode(), 200)
|
||||
m.AssertTook(timer, 300, 750)
|
||||
m.assertEqual(m.Hits("/seq/sharedretry/503,200"), 2)
|
||||
end function
|
||||
|
||||
@it("takes only its own answer when fetches share the port")
|
||||
function _()
|
||||
port = CreateObject("roMessagePort")
|
||||
timer = CreateObject("roTimespan")
|
||||
slow = HttpClient.Get(m.ServerUrl("/seq/sharedslow/202@500")).SendOn(port)
|
||||
fast = HttpClient.Get(m.ServerUrl("/seq/sharedfast/201@100")).SendOn(port)
|
||||
fastResponse = invalid
|
||||
fastMs = -1
|
||||
slowResponse = invalid
|
||||
while slowResponse = invalid and timer.TotalMilliseconds() < 3000
|
||||
waitMs = slow.MaxWaitMs()
|
||||
if fastResponse = invalid and fast.MaxWaitMs() < waitMs
|
||||
waitMs = fast.MaxWaitMs()
|
||||
end if
|
||||
message = wait(waitMs, port)
|
||||
if fastResponse = invalid
|
||||
fastResponse = fast.Handle(message)
|
||||
if fastResponse <> invalid
|
||||
fastMs = timer.TotalMilliseconds()
|
||||
end if
|
||||
end if
|
||||
slowResponse = slow.Handle(message)
|
||||
end while
|
||||
m.assertEqual(fastResponse.StatusCode(), 201)
|
||||
m.assertTrue(fastMs >= 100 and fastMs < 250, `fast took ${fastMs} ms`)
|
||||
m.assertEqual(slowResponse.StatusCode(), 202)
|
||||
m.AssertTook(timer, 500, 700)
|
||||
end function
|
||||
|
||||
@it("is cancelled at its cancellation's event, not at the loop's own node events")
|
||||
function _()
|
||||
cancellation = m.CreateCancellation()
|
||||
loop = m.CreateLoop()
|
||||
pending = HttpClient.Get(m.ServerUrl("/delay/3000")).Cancellation(cancellation).SendOn(loop.port)
|
||||
loop.node.ping = 1
|
||||
m.assertInvalid(pending.Handle(wait(1000, loop.port)))
|
||||
cancellation.node.cancel = true
|
||||
m.assertTrue(pending.Handle(wait(1000, loop.port)).IsCancelled())
|
||||
end function
|
||||
|
||||
@it("ignores another fetch's cancellation event when it has no cancellation of its own")
|
||||
function _()
|
||||
loop = m.CreateLoop()
|
||||
cancellation = m.CreateCancellation()
|
||||
cancelled = HttpClient.Get(m.ServerUrl("/delay/3000")).Cancellation(cancellation).SendOn(loop.port)
|
||||
uncancellable = HttpClient.Get(m.ServerUrl("/delay/200")).SendOn(loop.port)
|
||||
cancellation.node.cancel = true
|
||||
message = wait(1000, loop.port)
|
||||
m.assertEqual(message.GetNode(), "HttpClient.CancellationObserver")
|
||||
m.assertInvalid(uncancellable.Handle(message))
|
||||
m.assertTrue(cancelled.Handle(message).IsCancelled())
|
||||
m.assertEqual(m.RunSharedLoop(loop, uncancellable, 3000).StatusCode(), 200)
|
||||
end function
|
||||
|
||||
@it("completes a cache hit, a request not sent or a cancellation before it starts with no message, MaxWaitMs 1")
|
||||
function _()
|
||||
port = CreateObject("roMessagePort")
|
||||
cached = m.GetWithoutCacheEntry("/maxage/60/shared")
|
||||
cached.Await()
|
||||
cancellation = m.CreateCancellation()
|
||||
cancellation.node.cancel = true
|
||||
m.stubCall(HttpClient.CreateUrlTransfer, invalid)
|
||||
for each pending in [cached.SendOn(port), HttpClient.Get(m.ServerUrl("/status/200")).SendOn(port), HttpClient.Get(m.ServerUrl("/status/200")).Cancellation(cancellation).SendOn(port)]
|
||||
m.assertEqual(pending.MaxWaitMs(), 1)
|
||||
m.assertNotInvalid(pending.Handle(invalid))
|
||||
end for
|
||||
m.assertInvalid(port.GetMessage())
|
||||
end function
|
||||
|
||||
@describe("HttpClient cancellation")
|
||||
|
||||
@it("sends nothing when cancelled before Send")
|
||||
@@ -1523,6 +1653,22 @@ namespace Tests
|
||||
pending.Await()
|
||||
end function
|
||||
|
||||
@it("Await, Wait or Poll on a SendOn fetch")
|
||||
function _()
|
||||
port = CreateObject("roMessagePort")
|
||||
pending = HttpClient.Get(m.ServerUrl("/status/200")).SendOn(port)
|
||||
m.AssertContains(m.ThrownMessage(function(pending as object) as void
|
||||
pending.Await()
|
||||
end function, pending), "Await, Wait or Poll on a SendOn fetch")
|
||||
m.AssertContains(m.ThrownMessage(function(pending as object) as void
|
||||
pending.Wait(100)
|
||||
end function, pending), "Await, Wait or Poll on a SendOn fetch")
|
||||
m.AssertContains(m.ThrownMessage(function(pending as object) as void
|
||||
pending.Poll()
|
||||
end function, pending), "Await, Wait or Poll on a SendOn fetch")
|
||||
pending.Cancel()
|
||||
end function
|
||||
|
||||
@it("Text or Json on a response whose body was saved to a file")
|
||||
function _()
|
||||
response = HttpClient.Get(m.ServerUrl("/status/200")).SaveBodyToFile("tmp:/http-misuse.txt").Await()
|
||||
|
||||
Reference in new issue
Block a user