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
|
||||
## reads it, potentially raising an exception if the future failed or was
|
||||
## cancelled.
|
||||
while not(fut.finished()):
|
||||
poll()
|
||||
|
||||
var finished = false
|
||||
# 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()
|
||||
|
||||
proc asyncSpawn*(future: Future[void]) =
|
||||
|
|
|
@ -54,7 +54,6 @@ suite "Future[T] behavior test suite":
|
|||
fut.addCallback proc(udata: pointer) =
|
||||
testResult &= "5"
|
||||
discard waitFor(fut)
|
||||
poll()
|
||||
|
||||
check:
|
||||
fut.finished
|
||||
|
@ -80,7 +79,6 @@ suite "Future[T] behavior test suite":
|
|||
fut.addCallback cb5
|
||||
fut.removeCallback cb3
|
||||
discard waitFor(fut)
|
||||
poll()
|
||||
check:
|
||||
fut.finished
|
||||
testResult == "1245"
|
||||
|
@ -1260,12 +1258,12 @@ suite "Future[T] behavior test suite":
|
|||
(loc.procedure == procedure)
|
||||
|
||||
check:
|
||||
chk(loc10, "testfut.nim", 1227, "macroFuture")
|
||||
chk(loc11, "testfut.nim", 1230, "")
|
||||
chk(loc20, "testfut.nim", 1239, "template")
|
||||
chk(loc21, "testfut.nim", 1242, "")
|
||||
chk(loc30, "testfut.nim", 1236, "procedure")
|
||||
chk(loc31, "testfut.nim", 1243, "")
|
||||
chk(loc10, "testfut.nim", 1225, "macroFuture")
|
||||
chk(loc11, "testfut.nim", 1228, "")
|
||||
chk(loc20, "testfut.nim", 1237, "template")
|
||||
chk(loc21, "testfut.nim", 1240, "")
|
||||
chk(loc30, "testfut.nim", 1234, "procedure")
|
||||
chk(loc31, "testfut.nim", 1241, "")
|
||||
|
||||
asyncTest "withTimeout(fut) should wait cancellation test":
|
||||
proc futureNeverEnds(): Future[void] =
|
||||
|
|
|
@ -187,11 +187,11 @@ suite "HTTP client testing suite":
|
|||
let ResponseTests = [
|
||||
(MethodGet, "/test/short_size_response", 65600, 1024,
|
||||
"SHORTSIZERESPONSE"),
|
||||
(MethodGet, "/test/long_size_response", 262400, 1024,
|
||||
(MethodGet, "/test/long_size_response", 131200, 1024,
|
||||
"LONGSIZERESPONSE"),
|
||||
(MethodGet, "/test/short_chunked_response", 65600, 1024,
|
||||
"SHORTCHUNKRESPONSE"),
|
||||
(MethodGet, "/test/long_chunked_response", 262400, 1024,
|
||||
(MethodGet, "/test/long_chunked_response", 131200, 1024,
|
||||
"LONGCHUNKRESPONSE")
|
||||
]
|
||||
proc process(r: RequestFence): Future[HttpResponseRef] {.
|
||||
|
|
|
@ -34,7 +34,7 @@ ping -n 10 127.0.0.1 > NUL
|
|||
EXIT 0
|
||||
|
||||
:BIGDATA
|
||||
FOR /L %%G IN (1, 1, 400000) DO ECHO ALICEWASBEGINNINGTOGETVERYTIREDOFSITTINGBYHERSISTERONTHEBANKANDO
|
||||
FOR /L %%G IN (1, 1, 100000) DO ECHO ALICEWASBEGINNINGTOGETVERYTIREDOFSITTINGBYHERSISTERONTHEBANKANDO
|
||||
EXIT 0
|
||||
|
||||
:ENVTEST
|
||||
|
|
|
@ -214,9 +214,9 @@ suite "Asynchronous process management test suite":
|
|||
"tests/testproc.sh bigdata"
|
||||
let expect =
|
||||
when defined(windows):
|
||||
400_000 * (64 + 2)
|
||||
100_000 * (64 + 2)
|
||||
else:
|
||||
400_000 * (64 + 1)
|
||||
100_000 * (64 + 1)
|
||||
let process = await startProcess(command, options = options,
|
||||
stdoutHandle = AsyncProcess.Pipe,
|
||||
stderrHandle = AsyncProcess.Pipe)
|
||||
|
|
|
@ -12,7 +12,7 @@ elif [ "$1" == "timeout2" ]; then
|
|||
elif [ "$1" == "timeout10" ]; then
|
||||
sleep 10
|
||||
elif [ "$1" == "bigdata" ]; then
|
||||
for i in {1..400000}
|
||||
for i in {1..100000}
|
||||
do
|
||||
echo "ALICEWASBEGINNINGTOGETVERYTIREDOFSITTINGBYHERSISTERONTHEBANKANDO"
|
||||
done
|
||||
|
|
|
@ -75,11 +75,6 @@ suite "Asynchronous utilities test suite":
|
|||
pendingFuturesCount() == 2'u
|
||||
|
||||
waitFor fut
|
||||
check:
|
||||
getCount() == 1'u
|
||||
pendingFuturesCount() == 1'u
|
||||
|
||||
poll()
|
||||
check:
|
||||
getCount() == 0'u
|
||||
pendingFuturesCount() == 0'u
|
||||
|
|
Loading…
Reference in New Issue