Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Krastanov committed Aug 3, 2023
1 parent e9fab94 commit def37ca
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
ResumableFunctions = "c5292f4c-5179-55e1-98c5-05642aab7184"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ println("Starting tests with $(Threads.nthreads()) threads out of `Sys.CPU_THREA
@doset "resources_containers_deprecated"
@doset "resources_stores"
@doset "resources_stores_deprecated"
@doset "resources_tracked"
@doset "utils_time"
VERSION >= v"1.9" && @doset "doctests"
VERSION >= v"1.9" && @doset "aqua"
Expand Down
39 changes: 39 additions & 0 deletions test/test_resources_tracked.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using ConcurrentSim
using ResumableFunctions
using Test
using DataFrames, Tables

struct StoreObject
i :: Int
end

@resumable function my_consumer(sim::Simulation, sto)
for j in 1:10
@yield timeout(sim, rand())
println("$(now(sim)), consumer is demanding object")
obj = @yield take!(sto)
println("$(now(sim)), consumer is being served with object ", obj.i)
end
end

@resumable function my_producer(sim::Simulation, sto)
for j in 1:10
println("$(now(sim)), producer is offering object $j")
@yield put!(sto, StoreObject(j))
println("$(now(sim)), producer is being served")
@yield timeout(sim, 2*rand())
end
end

sim = Simulation()
sto = TrackedResource(Store{StoreObject}(sim))
@process my_consumer(sim, sto)
@process my_producer(sim, sto)
run(sim)

df = DataFrame(sto)
@test df[!,:events] == Tables.getcolumn(sto, 1)
@test df[!,:times] == Tables.getcolumn(sto, 2)

@test_throws ErrorException Tables.getcolumn(sto, 3)
@test_throws ErrorException Tables.getcolumn(sto, :lala)

0 comments on commit def37ca

Please sign in to comment.