From 9b8a4598cd98ba9810ed05ed4b697b0625820d44 Mon Sep 17 00:00:00 2001 From: Abel Braaksma Date: Mon, 24 Oct 2022 14:48:06 +0200 Subject: [PATCH] Show that the NRE can also occur in synchronous versions of taskSeq --- .../TaskSeq.StateTransitionBug.Tests.CE.fs | 147 +++++++++++++++++- 1 file changed, 145 insertions(+), 2 deletions(-) diff --git a/src/FSharpy.TaskSeq.Test/TaskSeq.StateTransitionBug.Tests.CE.fs b/src/FSharpy.TaskSeq.Test/TaskSeq.StateTransitionBug.Tests.CE.fs index 43c0bbec..06e4e190 100644 --- a/src/FSharpy.TaskSeq.Test/TaskSeq.StateTransitionBug.Tests.CE.fs +++ b/src/FSharpy.TaskSeq.Test/TaskSeq.StateTransitionBug.Tests.CE.fs @@ -315,7 +315,7 @@ let ``CE taskSeq, call GetAsyncEnumerator twice -- random mixed iteration`` () = } [] -let ``CE taskSeq with two items, call map multiple times over its own result`` () = task { +let ``CE taskSeq, call map multiple times over its own result`` () = task { let tskSeq = taskSeq { yield 1 yield 2 @@ -333,7 +333,150 @@ let ``CE taskSeq with two items, call map multiple times over its own result`` ( } [] -let ``CE taskSeq with two items, call mapAsync multiple times over its own result`` () = task { +let ``CE taskSeq, call map multiple times over its own result - alternative #1`` () = task { + let tskSeq1 = taskSeq { + yield 1 + yield 2 + } + + // [ 2; 3] + let tskSeq2 = taskSeq { + for i in tskSeq1 do + yield i + 1 + } + + // [ 3; 4] + let tskSeq3 = taskSeq { + for i in tskSeq2 do + yield i + 1 + } + + let result3 = TaskSeq.toArray tskSeq3 + + result3 |> should equal [| 3; 4 |] +} + +[] +let ``CE taskSeq, call map multiple times over its own result - alternative #2`` () = task { + let tskSeq1 = taskSeq { + yield 1 + yield 2 + } + + let result1 = TaskSeq.toArray tskSeq1 + result1 |> should equal [| 1; 2 |] + + // [ 2; 3] + let tskSeq2 = taskSeq { + for i in tskSeq1 do + yield i + 1 + } + + let result2 = TaskSeq.toArray tskSeq2 + result2 |> should equal [| 2; 3 |] + + // [ 3; 4] + let tskSeq3 = taskSeq { + for i in tskSeq2 do + yield i + 1 + } + + let result3 = TaskSeq.toArray tskSeq3 + result3 |> should equal [| 3; 4 |] +} + +[] +let ``CE taskSeq, call map multiple times over its own result - alternative #3`` () = task { + let tskSeq1 = taskSeq { + yield 1 + yield 2 + } + + let result1 = TaskSeq.toArray tskSeq1 + result1 |> should equal [| 1; 2 |] + + // [ 2; 3] + let tskSeq2 = taskSeq { + yield! taskSeq { + for i in tskSeq1 do + yield i + 1 + } + } + + let result2 = TaskSeq.toArray tskSeq2 + result2 |> should equal [| 2; 3 |] + + // [ 3; 4] + let tskSeq3 = taskSeq { + yield! taskSeq { + for i in tskSeq2 do + yield i + 1 + } + } + + let result3 = TaskSeq.toArray tskSeq3 + result3 |> should equal [| 3; 4 |] +} + +[] +let ``CE taskSeq, call map multiple times over its own result - alternative #4`` () = task { + let sequence = seq { + yield 1 + yield 2 + } + + // [ 2; 3] + let tskSeq2 = taskSeq { + for i in sequence do + yield i + 1 + } + + let result2 = TaskSeq.toArray tskSeq2 + result2 |> should equal [| 2; 3 |] + + // [ 3; 4] + let tskSeq3 = taskSeq { + for i in tskSeq2 do + yield i + 1 + } + + let result3 = TaskSeq.toArray tskSeq3 + result3 |> should equal [| 3; 4 |] +} + +[] +let ``CE taskSeq, call map multiple times over its own result - alternative #5`` () = task { + let sequence = seq { + yield 1 + yield 2 + } + + // [ 2; 3] + let tskSeq2 = taskSeq { + yield! taskSeq { + for i in sequence do + yield i + 1 + } + } + + let result2 = TaskSeq.toArray tskSeq2 + result2 |> should equal [| 2; 3 |] + + // [ 3; 4] + let tskSeq3 = taskSeq { + yield! taskSeq { + for i in tskSeq2 do + yield i + 1 + } + } + + let result3 = TaskSeq.toArray tskSeq3 + result3 |> should equal [| 3; 4 |] +} + + +[] +let ``CE taskSeq, call mapAsync multiple times over its own result`` () = task { let tskSeq = taskSeq { yield 1 yield 2