From dc74a5edff847e00433e2ac05fde96c5c4b8c4e4 Mon Sep 17 00:00:00 2001 From: Simon Etter Date: Wed, 22 Mar 2023 15:35:11 +0800 Subject: [PATCH] test(receive): Make sure received messages are removed from the queue, and test both blocking and non-blocking receives --- test/runtests.jl | 59 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index dd899ca..b2ac7b3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -61,12 +61,38 @@ try @test isa(MyReq(), MyAbstractReq) end - @testset "send & receive (gw)" begin + @testset "send & receive (gw, blocking)" begin flush(gw) + channel = Channel() + errormonitor(@async put!(channel, receive(gw, 1000))) + yield() send(gw, ShellExecReq(recipient=shell, cmd="1+2")) - rsp = receive(gw, 1000) + rsp = take!(channel) + @test typeof(rsp) <: Message + @test rsp.performative == "AGREE" + + # Make sure response is removed + rsp = receive(gw) + @test isnothing(rsp) + end + + @testset "send & receive (gw, nonblocking)" begin + flush(gw) + send(gw, ShellExecReq(recipient=shell, cmd="1+2")) + rsp = nothing + for _ = 1:10 + rsp = receive(gw) + if !isnothing(rsp) + break + end + sleep(0.1) + end @test typeof(rsp) <: Message @test rsp.performative == "AGREE" + + # Make sure response is removed + rsp = receive(gw) + @test isnothing(rsp) end @testset "send & receive (aid)" begin @@ -137,11 +163,36 @@ try @test typeof(msg) <: ShellExecReq end - @testset "receive (filt, +)" begin + @testset "receive (filt, +, blocking)" begin flush(gw) + channel = Channel() + errormonitor(@async put!(channel, receive(gw, ShellExecReq, 1000))) + yield() send(ntf, ShellExecReq(cmd="1+2")) - msg = receive(gw, ShellExecReq, 1000) + msg = take!(channel) @test typeof(msg) <: ShellExecReq + + # Make sure response is removed + msg = receive(gw, ShellExecReq) + @test isnothing(msg) + end + + @testset "receive (filt, +, nonblocking)" begin + flush(gw) + send(ntf, ShellExecReq(cmd="1+2")) + msg = nothing + for _ = 1:10 + msg = receive(gw, ShellExecReq) + if !isnothing(msg) + break + end + sleep(0.1) + end + @test typeof(msg) <: ShellExecReq + + # Make sure response is removed + msg = receive(gw, ShellExecReq) + @test isnothing(msg) end UnknownReq = MessageClass(@__MODULE__, "org.arl.fjage.shell.UnknownReq")