Skip to content

Commit def37ca

Browse files
committed
more tests
1 parent e9fab94 commit def37ca

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

test/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1010
ResumableFunctions = "c5292f4c-5179-55e1-98c5-05642aab7184"
1111
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
1212
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
13+
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
1314
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ println("Starting tests with $(Threads.nthreads()) threads out of `Sys.CPU_THREA
3535
@doset "resources_containers_deprecated"
3636
@doset "resources_stores"
3737
@doset "resources_stores_deprecated"
38+
@doset "resources_tracked"
3839
@doset "utils_time"
3940
VERSION >= v"1.9" && @doset "doctests"
4041
VERSION >= v"1.9" && @doset "aqua"

test/test_resources_tracked.jl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using ConcurrentSim
2+
using ResumableFunctions
3+
using Test
4+
using DataFrames, Tables
5+
6+
struct StoreObject
7+
i :: Int
8+
end
9+
10+
@resumable function my_consumer(sim::Simulation, sto)
11+
for j in 1:10
12+
@yield timeout(sim, rand())
13+
println("$(now(sim)), consumer is demanding object")
14+
obj = @yield take!(sto)
15+
println("$(now(sim)), consumer is being served with object ", obj.i)
16+
end
17+
end
18+
19+
@resumable function my_producer(sim::Simulation, sto)
20+
for j in 1:10
21+
println("$(now(sim)), producer is offering object $j")
22+
@yield put!(sto, StoreObject(j))
23+
println("$(now(sim)), producer is being served")
24+
@yield timeout(sim, 2*rand())
25+
end
26+
end
27+
28+
sim = Simulation()
29+
sto = TrackedResource(Store{StoreObject}(sim))
30+
@process my_consumer(sim, sto)
31+
@process my_producer(sim, sto)
32+
run(sim)
33+
34+
df = DataFrame(sto)
35+
@test df[!,:events] == Tables.getcolumn(sto, 1)
36+
@test df[!,:times] == Tables.getcolumn(sto, 2)
37+
38+
@test_throws ErrorException Tables.getcolumn(sto, 3)
39+
@test_throws ErrorException Tables.getcolumn(sto, :lala)

0 commit comments

Comments
 (0)