Skip to content

Commit

Permalink
Add cutoffprot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hanakl committed Jan 6, 2025
1 parent dc602ef commit 9f72869
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/ProtocolZoo/cutoff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ end

unlock(slot)
end
if !isnothing(prot.period)
if isnothing(prot.period)
@yield onchange_tag(reg)

Check warning on line 73 in src/ProtocolZoo/cutoff.jl

View check run for this annotation

Codecov / codecov/patch

src/ProtocolZoo/cutoff.jl#L73

Added line #L73 was not covered by tests
else
@yield timeout(prot.sim, prot.period)

Check warning on line 75 in src/ProtocolZoo/cutoff.jl

View check run for this annotation

Codecov / codecov/patch

src/ProtocolZoo/cutoff.jl#L75

Added line #L75 was not covered by tests
end
end
Expand Down
6 changes: 5 additions & 1 deletion src/semaphore.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using ConcurrentSim
using ResumableFunctions
import Base: unlock, lock
import Base: unlock, lock, islocked

"""Multiple processes can wait on this semaphore for a permission to run given by another process"""
struct AsymmetricSemaphore
Expand All @@ -27,3 +27,7 @@ function unlock(s::AsymmetricSemaphore)
unlock(s.lock)
end
end

function islocked(s::AsymmetricSemaphore)
return islocked(s.lock)

Check warning on line 32 in src/semaphore.jl

View check run for this annotation

Codecov / codecov/patch

src/semaphore.jl#L31-L32

Added lines #L31 - L32 were not covered by tests
end
32 changes: 32 additions & 0 deletions test/test_protocolzoo_cutoffprot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,36 @@ run(sim, 2.0)
run(sim, 6.0)
@test !isassigned(net[1][1])
@test isassigned(net[2][1])

# test for period=nothing
net = RegisterNet([Register(2), Register(1)])
sim = get_time_tracker(net)
initialize!((net[1][1], net[2][1]), (Z1Z1+Z2Z2)/(sqrt(2.0)))
tag!(net[1][1], EntanglementCounterpart, 2, 1)
tag!(net[2][1], EntanglementCounterpart, 1, 1)

cprot1 = CutoffProt(sim, net, 1; period=nothing, retention_time=3.0)
cprot2 = CutoffProt(sim, net, 2; period=0.1, retention_time=3.0)
@process cprot1()
@process cprot2()

@resumable function wait_and_tag(sim)
@yield timeout(sim, 5)
tag!(net[1][2], Int)
end

@process wait_and_tag(sim)

run(sim, 2.0)
@test isassigned(net[1][1])
@test isassigned(net[2][1])

run(sim, 4.0)
@test isassigned(net[1][1])
@test !isassigned(net[2][1])

run(sim, 6.0)
@test !isassigned(net[1][1])
@test !isassigned(net[1][1])

end

0 comments on commit 9f72869

Please sign in to comment.