Skip to content

Commit

Permalink
Some initial tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamed2 committed Oct 22, 2015
1 parent f1cb675 commit c55ccd7
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions test/singlethreaded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,48 @@ using FactCheck
using ReadWriteLocks

facts("Single-threaded tests") do
context("Constructor") do
context("Initialization") do
rwlock = ReadWriteLock()

@fact rwlock.read_lock.rwlock -> rwlock
@fact rwlock.write_lock.rwlock -> rwlock
@fact rwlock.read_lock.rwlock --> rwlock
@fact rwlock.write_lock.rwlock --> rwlock
@fact rwlock.readers --> 0
@fact rwlock.writer --> false
@fact read_lock(rwlock) --> rwlock.read_lock
@fact write_lock(rwlock) --> rwlock.write_lock
end
end

facts("Two-threaded tests") do
context("Read locks") do
rwlock = ReadWriteLock()
rlock = read_lock(rwlock)

NUM_LOCKS = 10

@async begin
@fact rwlock.readers --> 0
for i = 1:NUM_LOCKS
@fact lock!(rlock) --> nothing
@fact rwlock.readers --> i
end
end

sleep(1)

@fact rwlock.readers --> NUM_LOCKS

@async begin
@fact rwlock.readers --> NUM_LOCKS
for i = NUM_LOCKS:-1:1
@fact unlock!(rlock) --> nothing
@fact rwlock.readers --> i - 1
end
@fact rwlock.readers --> 0
end

sleep(1)

@fact rwlock.readers --> 0
end
end

0 comments on commit c55ccd7

Please sign in to comment.