From ffc580549b515d31ddf4adfaa31ff7b04b3ffa2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20B=C3=B6ck?= Date: Wed, 17 Jan 2024 09:37:15 +0100 Subject: [PATCH] add test case --- src/tapedfunction.jl | 1 + test/tape_copy.jl | 24 ++++++++++++------------ test/tapedtask.jl | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/tapedfunction.jl b/src/tapedfunction.jl index c622818..405ce3d 100644 --- a/src/tapedfunction.jl +++ b/src/tapedfunction.jl @@ -221,6 +221,7 @@ function (instr::Instruction{F})(tf::TapedFunction, callback=nothing) where F func(inputs...) else tf_inner = get!(tf.subtapes, instr, TapedFunction(func, inputs..., cache=true)) + # continuation=false breaks "Multiple func calls subtapes" and "Copying task with subtapes" tf_inner(inputs...; callback=callback, continuation=true) end _update_var!(tf, instr.output, output) diff --git a/test/tape_copy.jl b/test/tape_copy.jl index 63f4fa3..d3d05cb 100644 --- a/test/tape_copy.jl +++ b/test/tape_copy.jl @@ -194,18 +194,18 @@ end @testset "Copying task with subtapes" begin - function f() + function f2() produce(1) produce(2) end - function g() - f() + function g2() + f2() end - Libtask.is_primitive(::typeof(f), args...) = false + Libtask.is_primitive(::typeof(f2), args...) = false - ttask = TapedTask(g) + ttask = TapedTask(g2) @test consume(ttask) == 1 ttask2 = copy(ttask) @@ -217,19 +217,19 @@ end @testset "Multiple func calls subtapes" begin - function f() + function f3() produce(1) produce(2) end - function g() - f() - f() + function g3() + f3() + f3() end - Libtask.is_primitive(::typeof(f), args...) = false + Libtask.is_primitive(::typeof(f3), args...) = false - ttask = TapedTask(g) + ttask = TapedTask(g3) @test consume(ttask) == 1 ttask2 = copy(ttask) @@ -248,4 +248,4 @@ @test consume(ttask3) === nothing end -end \ No newline at end of file +end diff --git a/test/tapedtask.jl b/test/tapedtask.jl index 8d1b316..eaeadd0 100644 --- a/test/tapedtask.jl +++ b/test/tapedtask.jl @@ -169,5 +169,22 @@ ttask = TapedTask(g) @test_throws Exception consume(ttask) end + + @testset "Multiple producers for non-primitive" begin + function f2() + produce(1) + produce(2) + end + Libtask.is_primitive(::typeof(f2), args...) = false + + function g2() + f2() + end + + ttask = TapedTask(g2) + @test consume(ttask) == 1 + @test consume(ttask) == 2 + @test consume(ttask) === nothing + end end end \ No newline at end of file