Skip to content

Commit

Permalink
Remove sleep from crosstalk.
Browse files Browse the repository at this point in the history
  • Loading branch information
dom96 committed Dec 15, 2021
1 parent 869eb42 commit 5202b4c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/httpbeast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,9 @@ proc run*(onRequest: OnRequest, settings: Settings) =
createThread[(OnRequest, Settings)](
t, eventLoop, (onRequest, settings)
)
echo("Listening on port ", settings.port) # This line is used in the tester to signal readiness.
else:
assert false
echo("Listening on port ", settings.port) # This line is used in the tester to signal readiness.
eventLoop((onRequest, settings))

proc run*(onRequest: OnRequest) {.inline.} =
Expand Down
16 changes: 11 additions & 5 deletions tests/crosstalk.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ proc nonAwaitedDelayedSend(req: Request, id: string) {.async.} =
req.send("Delayed " & id)

var lastFd = -1
proc onRequest(req: Request) {.async.} =
var nonClosedFirst = newFuture[void]()
var closedFirst = newFuture[void]()
proc onRequest(req: Request) {.async, gcsafe.} =
if req.httpMethod == some(HttpGet):
let id = req.path.get()
case id
of "/":
req.send("Immediate")
of "/1", "/2":
# TODO: Can we replace this sleep?
await sleepAsync(1_000)
if id == "/1":
await nonClosedFirst
else:
nonClosedFirst.complete()
echo("Sleep finished, responding to request ", id)
req.send("Delayed " & id)
of "/close_me/1", "/close_me/2":
# To reproduce this bug we expect the OS to reuse the OS.
# To reproduce this bug we expect the OS to reuse the FDs.
if lastFd == -1:
lastFd = req.client.int
else:
Expand All @@ -32,7 +36,9 @@ proc onRequest(req: Request) {.async.} =
if id.endsWith("/1"):
req.forget()
req.client.close()
await sleepAsync(1_000)
await closedFirst
else:
closedFirst.complete()
echo("Sleep finished, responding to request ", id)
try:
req.send("Delayed " & id)
Expand Down
2 changes: 2 additions & 0 deletions tests/crosstalk.nim.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--threadAnalysis:off
--threads:off

0 comments on commit 5202b4c

Please sign in to comment.