Skip to content

Commit

Permalink
Fix hang when requests limit is set
Browse files Browse the repository at this point in the history
Delete old tests
  • Loading branch information
lolgab committed May 1, 2024
1 parent 61987a0 commit d0a1cf8
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 145 deletions.
54 changes: 0 additions & 54 deletions integration/test/src/BaseTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,66 +47,12 @@ object BaseTests extends TestSuite {
}
}
}
test("async") {
withDeployedExample("async") {
val result = request.get(baseUrl).text()
val expectedResult = "Hello world async!\n"
assert(result == expectedResult)
}
}
test("async-epollcat") {
withDeployedExample("async-epollcat") {
val result = request.get(baseUrl).text()
val expectedResult = "Hello world from epollcat!"
assert(result == expectedResult)
}
}
test("async-epollcat-unit-requests-limits") {
withDeployedExample("async-epollcat") {
val limitsResult = os
.proc(
if (sys.env.contains("CI")) Seq("sudo") else Seq.empty[String],
"curl",
"-s",
"--unix-socket",
BuildInfo.unitControl,
"-XPUT",
"-d",
"""{"requests": 1}""",
"localhost/config/applications/app/limits"
)
.call()
.out
.text()
.replaceAll("\\s+", "")
assert(limitsResult == """{"success":"Reconfigurationdone."}""")
Thread.sleep(1000)
for (i <- 0.to(10)) {
val result = request.get(baseUrl).text()
val expectedResult = "Hello world from epollcat!"
assert(result == expectedResult)
}
}
}
test("multiple-handlers") {
withDeployedExample("multiple-handlers") {
val getResult = request.get(baseUrl).text()
val expectedGetResult = "Hello world multiple handlers!\n"
assert(getResult == expectedGetResult)

val postResultResponse = request.post(baseUrl)
val postResult = postResultResponse.text()
val expectedPostResult = "Not found\n"
assert(postResult == expectedPostResult)
assert(postResultResponse.statusCode() == 404)
}
}
test("async-multiple-handlers") {
withDeployedExample("async-multiple-handlers") {
val getResult = request.get(baseUrl).text()
val expectedGetResult = "Hello world async multiple handlers!\n"
assert(getResult == expectedGetResult)

val postResultResponse = request.post(baseUrl)
val postResult = postResultResponse.text()
val expectedPostResult = "Not found\n"
Expand Down
5 changes: 0 additions & 5 deletions integration/test/src/TapirTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ object TapirTests extends TestSuite {
tapirHelloWorldTest(baseUrl)
}
}
test("tapir-helloworld-future") {
withDeployedExample("tapir-helloworld-future") {
tapirHelloWorldTest(baseUrl)
}
}
test("tapir-helloworld-cats-effect") {
withDeployedExample("tapir-helloworld-cats-effect") {
tapirHelloWorldTest(baseUrl)
Expand Down

This file was deleted.

This file was deleted.

33 changes: 0 additions & 33 deletions integration/tests/async/src/snunit/tests/Async.scala

This file was deleted.

15 changes: 1 addition & 14 deletions snunit-async-cats-effect/src/snunit/CEAsyncServerBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,6 @@ private[snunit] object CEAsyncServerBuilder {
) {
private var stopped: Boolean = false

// ideally this shouldn't be needed.
// in theory rc == NXT_UNIT_AGAIN
// would mean that there aren't any messages
// to read. In practice if we stop at rc == NXT_UNIT_AGAIN
// there are some unprocessed messages which effect in
// epollcat (which uses edge-triggering) to hang on close
// since one port to remain open and one callback registered
def continueReading: Boolean = {
val bytesAvailable = stackalloc[Int]()
ioctl(port.in_fd, FIONREAD, bytesAvailable.asInstanceOf[Ptr[Byte]])
!bytesAvailable > 0
}

dispatcher
.unsafeRunAndForget(
poller
Expand All @@ -126,7 +113,7 @@ private[snunit] object CEAsyncServerBuilder {
.pollReadRec[Unit, Unit](()) { _ =>
IO {
// process messages until we are blocked
while (nxt_unit_process_port_msg(ctx, port) == NXT_UNIT_OK || continueReading) {}
while (nxt_unit_process_port_msg(ctx, port) == NXT_UNIT_OK) {}

if (stopped && PortData.isLastFDStopped)
Right(())
Expand Down

0 comments on commit d0a1cf8

Please sign in to comment.