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:
parent
9896316599
commit
8156e2997a
|
@ -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]) =
|
||||||
|
|
|
@ -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] =
|
||||||
|
|
|
@ -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] {.
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue