From ade1f3018e7913c28fec2e954832d5904d3bbfcb Mon Sep 17 00:00:00 2001 From: gmega Date: Tue, 28 Nov 2023 18:43:22 -0300 Subject: [PATCH] add failing test case for an async proc with children in its finally block --- tests/profiler/testevents.nim | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/profiler/testevents.nim b/tests/profiler/testevents.nim index 69caef7..86c21f7 100644 --- a/tests/profiler/testevents.nim +++ b/tests/profiler/testevents.nim @@ -107,4 +107,28 @@ suite "profiler hooks test suite": SimpleEvent(state: ExtendedFutureState.Running, procedure: "withChildren"), SimpleEvent(state: ExtendedFutureState.Running, procedure: "segment 2"), SimpleEvent(state: ExtendedFutureState.Completed, procedure: "withChildren"), - ] \ No newline at end of file + ] + + test "should not say a future is completed before children in finally blocks are run": + skip() + when false: + # TODO: chronos allows completed futures to generate children in their + # finally blocks. This causes a set of transitions that break our state + # machine. + proc withFinally(): Future[void] {.async.} = + try: + return + finally: + await sleepAsync(10.milliseconds) + + waitFor withFinally() + + check recording == @[ + SimpleEvent(state: Pending, procedure: "withFinally"), + SimpleEvent(state: ExtendedFutureState.Running, procedure: "withFinally"), + SimpleEvent(state: ExtendedFutureState.Pending, procedure: "chronos.sleepAsync(Duration)"), + SimpleEvent(state: ExtendedFutureState.Paused, procedure: "withFinally"), + SimpleEvent(state: ExtendedFutureState.Completed, procedure: "chronos.sleepAsync(Duration)"), + SimpleEvent(state: ExtendedFutureState.Running, procedure: "withFinally"), + SimpleEvent(state: ExtendedFutureState.Completed, procedure: "withFinally") + ]