-
Notifications
You must be signed in to change notification settings - Fork 60
Do not return to scheduler while completing {.async.} proc #668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
etan-status
wants to merge
18
commits into
master
Choose a base branch
from
dev/etan/ae-returnstrain
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+485
−43
Open
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b4bb2a8
Remove yield points while unwinding {.async.} proc
etan-status 5c1f769
Apply suggestion from @etan-status
etan-status a9a2746
Restore when jungle
etan-status 9695d1d
Add FutureFlag.SyncContinuations and opt-in config flag
etan-status 9fd38ca
Sync nimble.config patterns
etan-status 188f0b2
Rename new test file
etan-status fd0b6c9
Resolve multiple waiters in FIFO registration order
etan-status 15effb0
Update chronos/config.nim
etan-status de0f175
Extend to all continuations, not just await continuations
etan-status 194c456
Merge branch 'master' into dev/etan/ae-returnstrain
etan-status 0352e6e
Match existing skip style
etan-status 216fb74
Delay waitFor continuation to include existing other callbacks
etan-status 02b4b6a
Add combinator tests
etan-status ce44964
Should not change consumer code
etan-status c5995e7
Flag to treat non-`{.async.}` callbacks as continuations
etan-status 1c7b440
Apply suggestion from @etan-status
etan-status 324499b
Merge branch 'master' into dev/etan/ae-returnstrain
etan-status b0a4008
Merge commit '637d96d30cb06109b69c07b63b758c934ec17503' into dev/etan…
etan-status File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| # Chronos Test Suite | ||
| # (c) Copyright 2026-Present | ||
| # Status Research & Development GmbH | ||
| # | ||
| # Licensed under either of | ||
| # Apache License, version 2.0, (LICENSE-APACHEv2) | ||
| # MIT license (LICENSE-MIT) | ||
| import unittest2 | ||
| import ../chronos | ||
|
|
||
| {.push raises: [], gcsafe.} | ||
| {.used.} | ||
|
|
||
| suite "Stack unwind scheduling test suite": | ||
| type Trace = seq[string] | ||
|
|
||
| proc runTest( | ||
| cb: proc ( | ||
| trace: ptr Trace | ||
| ): Future[void].Raising([CancelledError]) {.raises: [], gcsafe.} | ||
| ): Trace = | ||
| var trace: Trace | ||
| try: | ||
| waitFor cb(addr trace) | ||
| except CancelledError: | ||
| raiseAssert "Not cancelled" | ||
| trace | ||
|
|
||
| proc competitorCb(udata: pointer) = | ||
| cast[ptr Trace](udata)[].add "competitor" | ||
|
|
||
| proc observerCb(udata: pointer) = | ||
| cast[ptr Trace](udata)[].add "observer" | ||
|
|
||
| proc testValueReturn(): Trace = | ||
| proc producer( | ||
| trace: ptr Trace): Future[int] {.async: (raises: [CancelledError]).} = | ||
| await sleepAsync(ZeroDuration) | ||
| callSoon(competitorCb, trace) | ||
| trace[].add "producer returns" | ||
| 42 | ||
|
|
||
| proc consumer(trace: ptr Trace) {.async: (raises: [CancelledError]).} = | ||
| let v = await producer(trace) | ||
| trace[].add "consumer returns " & $v | ||
|
|
||
| runTest consumer | ||
|
|
||
| proc testFailingReturn(): Trace = | ||
| proc producer( | ||
| trace: ptr Trace | ||
| ): Future[int] {.async: (raises: [CancelledError, ValueError]).} = | ||
| await sleepAsync(ZeroDuration) | ||
| callSoon(competitorCb, trace) | ||
| trace[].add "producer raising" | ||
| raise newException(ValueError, "err") | ||
|
|
||
| proc consumer(trace: ptr Trace) {.async: (raises: [CancelledError]).} = | ||
| try: | ||
| discard await producer(trace) | ||
| except ValueError: | ||
| trace[].add "consumer caught" | ||
|
|
||
| runTest consumer | ||
|
|
||
| proc testMultiLevel(): Trace = | ||
| proc bottom( | ||
| trace: ptr Trace): Future[int] {.async: (raises: [CancelledError]).} = | ||
| await sleepAsync(ZeroDuration) | ||
| callSoon(competitorCb, trace) | ||
| trace[].add "bottom returns" | ||
| 1 | ||
|
|
||
| proc mid( | ||
| trace: ptr Trace): Future[int] {.async: (raises: [CancelledError]).} = | ||
| let v = await bottom(trace) | ||
| trace[].add "mid returns" | ||
| v + 1 | ||
|
|
||
| proc top(trace: ptr Trace) {.async: (raises: [CancelledError]).} = | ||
| let v = await mid(trace) | ||
| trace[].add "top returns " & $v | ||
|
|
||
| runTest top | ||
|
|
||
| proc testObserverReturn(): Trace = | ||
| proc producer( | ||
| trace: ptr Trace): Future[int] {.async: (raises: [CancelledError]).} = | ||
| await sleepAsync(ZeroDuration) | ||
| callSoon(competitorCb, trace) | ||
| trace[].add "producer returns" | ||
| 7 | ||
|
|
||
| proc consumer(trace: ptr Trace) {.async: (raises: [CancelledError]).} = | ||
| let fut = producer(trace) | ||
| fut.addCallback(observerCb, trace) | ||
| let v = await fut | ||
| trace[].add "consumer returns " & $v | ||
|
|
||
| runTest consumer | ||
|
|
||
| proc testObserverRaise(): Trace = | ||
| proc producer( | ||
| trace: ptr Trace | ||
| ): Future[int] {.async: (raises: [CancelledError, ValueError]).} = | ||
| await sleepAsync(ZeroDuration) | ||
| callSoon(competitorCb, trace) | ||
| trace[].add "producer raising" | ||
| raise newException(ValueError, "err") | ||
|
|
||
| proc consumer(trace: ptr Trace) {.async: (raises: [CancelledError]).} = | ||
| let fut = producer(trace) | ||
| fut.addCallback(observerCb, trace) | ||
| try: | ||
| discard await fut | ||
| except ValueError: | ||
| trace[].add "consumer caught" | ||
|
|
||
| runTest consumer | ||
|
|
||
| proc testManualWakeup(): Trace = | ||
| let fut = Future[void].Raising([CancelledError]).init() | ||
|
|
||
| proc producer(trace: ptr Trace) {.async: (raises: [CancelledError]).} = | ||
| await fut | ||
| trace[].add "producer returns" | ||
|
|
||
| proc consumer(trace: ptr Trace) {.async: (raises: [CancelledError]).} = | ||
| let w = producer(trace) | ||
| callSoon(competitorCb, trace) | ||
| fut.complete() | ||
| await w | ||
|
|
||
| runTest consumer | ||
|
|
||
| proc testFanout(): Trace = | ||
| proc produce( | ||
| trace: ptr Trace): Future[int] {.async: (raises: [CancelledError]).} = | ||
| await sleepAsync(ZeroDuration) | ||
| trace[].add "produced" | ||
| 42 | ||
|
|
||
| var trace: Trace | ||
| let shared = produce(addr trace) | ||
|
|
||
| proc subA( | ||
| trace: ptr Trace): Future[void] {.async: (raises: [CancelledError]).} = | ||
| discard await shared | ||
| trace[].add "subA" | ||
|
|
||
| proc subB( | ||
| trace: ptr Trace): Future[void] {.async: (raises: [CancelledError]).} = | ||
| discard await shared | ||
| trace[].add "subB" | ||
|
|
||
| proc strainA(trace: ptr Trace) {.async: (raises: [CancelledError]).} = | ||
| await subA(trace) | ||
| trace[].add "strainA" | ||
|
|
||
| proc strainB(trace: ptr Trace) {.async: (raises: [CancelledError]).} = | ||
| await subB(trace) | ||
| trace[].add "strainB" | ||
|
|
||
| try: | ||
| waitFor allFutures(strainA(addr trace), strainB(addr trace)) | ||
| except CancelledError: | ||
| raiseAssert "Not cancelled" | ||
| trace | ||
|
|
||
| test "Unwind not interrupted test": | ||
| check: | ||
| testValueReturn() == | ||
| @["producer returns", "consumer returns 42", "competitor"] | ||
| testFailingReturn() == | ||
| @["producer raising", "consumer caught", "competitor"] | ||
|
|
||
| test "Multi-level unwind not interrupted test": | ||
| check testMultiLevel() == | ||
| @["bottom returns", "mid returns", "top returns 2", "competitor"] | ||
|
|
||
| test "Observer deferred test": | ||
| check: | ||
| testObserverReturn() == | ||
| @["producer returns", "consumer returns 7", "competitor", "observer"] | ||
| testObserverRaise() == | ||
| @["producer raising", "consumer caught", "competitor", "observer"] | ||
|
|
||
| test "Manual wakeup interruptible test": | ||
| check testManualWakeup() == @["competitor", "producer returns"] | ||
|
|
||
| test "Fan-out depth-first test": | ||
| # Each strain unwinds to conclusion before the next strain begins. | ||
| # Executed in reverse registration order. | ||
| check testFanout() == | ||
| @["produced", "subB", "strainB", "subA", "strainA"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.