Fix not enough memory on i386. (#467)

* Fix waitFor() should not exit earlier last callback will be scheduled.

* Tune tests to use less memory.

* Fix `testutils`. There is no more last poll() needed.

* Update chronos/internal/asyncfutures.nim

---------

Co-authored-by: Jacek Sieka <jacek@status.im>
This commit is contained in:
Eugene Kabanov 2023-11-10 08:42:36 +02:00 committed by GitHub
parent 9896316599
commit 8156e2997a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 22 deletions

View File

@ -560,9 +560,13 @@ proc waitFor*[T](fut: Future[T]): T {.raises: [CatchableError].} =
## **Blocks** the current thread until the specified future finishes and ## **Blocks** the current thread until the specified future finishes and
## reads it, potentially raising an exception if the future failed or was ## reads it, potentially raising an exception if the future failed or was
## cancelled. ## cancelled.
while not(fut.finished()): var finished = false
poll() # Ensure that callbacks currently scheduled on the future run before returning
proc continuation(udata: pointer) {.gcsafe.} = finished = true
if not(fut.finished()):
fut.addCallback(continuation)
while not(finished):
poll()
fut.read() fut.read()
proc asyncSpawn*(future: Future[void]) = proc asyncSpawn*(future: Future[void]) =

View File

@ -54,7 +54,6 @@ suite "Future[T] behavior test suite":
fut.addCallback proc(udata: pointer) = fut.addCallback proc(udata: pointer) =
testResult &= "5" testResult &= "5"
discard waitFor(fut) discard waitFor(fut)
poll()
check: check:
fut.finished fut.finished
@ -80,7 +79,6 @@ suite "Future[T] behavior test suite":
fut.addCallback cb5 fut.addCallback cb5
fut.removeCallback cb3 fut.removeCallback cb3
discard waitFor(fut) discard waitFor(fut)
poll()
check: check:
fut.finished fut.finished
testResult == "1245" testResult == "1245"
@ -1260,12 +1258,12 @@ suite "Future[T] behavior test suite":
(loc.procedure == procedure) (loc.procedure == procedure)
check: check:
chk(loc10, "testfut.nim", 1227, "macroFuture") chk(loc10, "testfut.nim", 1225, "macroFuture")
chk(loc11, "testfut.nim", 1230, "") chk(loc11, "testfut.nim", 1228, "")
chk(loc20, "testfut.nim", 1239, "template") chk(loc20, "testfut.nim", 1237, "template")
chk(loc21, "testfut.nim", 1242, "") chk(loc21, "testfut.nim", 1240, "")
chk(loc30, "testfut.nim", 1236, "procedure") chk(loc30, "testfut.nim", 1234, "procedure")
chk(loc31, "testfut.nim", 1243, "") chk(loc31, "testfut.nim", 1241, "")
asyncTest "withTimeout(fut) should wait cancellation test": asyncTest "withTimeout(fut) should wait cancellation test":
proc futureNeverEnds(): Future[void] = proc futureNeverEnds(): Future[void] =

View File

@ -187,11 +187,11 @@ suite "HTTP client testing suite":
let ResponseTests = [ let ResponseTests = [
(MethodGet, "/test/short_size_response", 65600, 1024, (MethodGet, "/test/short_size_response", 65600, 1024,
"SHORTSIZERESPONSE"), "SHORTSIZERESPONSE"),
(MethodGet, "/test/long_size_response", 262400, 1024, (MethodGet, "/test/long_size_response", 131200, 1024,
"LONGSIZERESPONSE"), "LONGSIZERESPONSE"),
(MethodGet, "/test/short_chunked_response", 65600, 1024, (MethodGet, "/test/short_chunked_response", 65600, 1024,
"SHORTCHUNKRESPONSE"), "SHORTCHUNKRESPONSE"),
(MethodGet, "/test/long_chunked_response", 262400, 1024, (MethodGet, "/test/long_chunked_response", 131200, 1024,
"LONGCHUNKRESPONSE") "LONGCHUNKRESPONSE")
] ]
proc process(r: RequestFence): Future[HttpResponseRef] {. proc process(r: RequestFence): Future[HttpResponseRef] {.

View File

@ -34,7 +34,7 @@ ping -n 10 127.0.0.1 > NUL
EXIT 0 EXIT 0
:BIGDATA :BIGDATA
FOR /L %%G IN (1, 1, 400000) DO ECHO ALICEWASBEGINNINGTOGETVERYTIREDOFSITTINGBYHERSISTERONTHEBANKANDO FOR /L %%G IN (1, 1, 100000) DO ECHO ALICEWASBEGINNINGTOGETVERYTIREDOFSITTINGBYHERSISTERONTHEBANKANDO
EXIT 0 EXIT 0
:ENVTEST :ENVTEST

View File

@ -214,9 +214,9 @@ suite "Asynchronous process management test suite":
"tests/testproc.sh bigdata" "tests/testproc.sh bigdata"
let expect = let expect =
when defined(windows): when defined(windows):
400_000 * (64 + 2) 100_000 * (64 + 2)
else: else:
400_000 * (64 + 1) 100_000 * (64 + 1)
let process = await startProcess(command, options = options, let process = await startProcess(command, options = options,
stdoutHandle = AsyncProcess.Pipe, stdoutHandle = AsyncProcess.Pipe,
stderrHandle = AsyncProcess.Pipe) stderrHandle = AsyncProcess.Pipe)

View File

@ -12,7 +12,7 @@ elif [ "$1" == "timeout2" ]; then
elif [ "$1" == "timeout10" ]; then elif [ "$1" == "timeout10" ]; then
sleep 10 sleep 10
elif [ "$1" == "bigdata" ]; then elif [ "$1" == "bigdata" ]; then
for i in {1..400000} for i in {1..100000}
do do
echo "ALICEWASBEGINNINGTOGETVERYTIREDOFSITTINGBYHERSISTERONTHEBANKANDO" echo "ALICEWASBEGINNINGTOGETVERYTIREDOFSITTINGBYHERSISTERONTHEBANKANDO"
done done

View File

@ -75,11 +75,6 @@ suite "Asynchronous utilities test suite":
pendingFuturesCount() == 2'u pendingFuturesCount() == 2'u
waitFor fut waitFor fut
check:
getCount() == 1'u
pendingFuturesCount() == 1'u
poll()
check: check:
getCount() == 0'u getCount() == 0'u
pendingFuturesCount() == 0'u pendingFuturesCount() == 0'u