Skip to content

Commit

Permalink
Split Concurrent::RWLock noracedetection tests into separate file (…
Browse files Browse the repository at this point in the history
…/build)
  • Loading branch information
64kramsystem committed Nov 16, 2017
1 parent 9c6e4af commit 512a44f
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 74 deletions.
81 changes: 81 additions & 0 deletions vm/concurrent_rw_lock_no_race_detection_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// +build noracedetection

package vm

import (
"testing"
)

// Mixed locks (functional tests)

func TestRWLockAcquireAndReleaseLocksReadBlocksWrite(t *testing.T) {
code := `
require 'concurrent/rw_lock'
lock = Concurrent::RWLock.new
message = nil
thread do
lock.acquire_read_lock
sleep 2
message ||= "thread 1"
lock.release_read_lock
end
thread do
sleep 1
lock.acquire_write_lock
message ||= "thread 2"
lock.release_write_lock
end
sleep 3
lock.with_read_lock do
message
end
`

expected := "thread 1"

v := initTestVM()
evaluated := v.testEval(t, code, getFilename())
testStringObject(t, i, evaluated, expected)
v.checkCFP(t, i, 0)
v.checkSP(t, i, 1)
}

func TestRWLockWithReadLockReadBlocksWrite(t *testing.T) {
code := `
require 'concurrent/rw_lock'
lock = Concurrent::RWLock.new
message = nil
thread do
lock.with_read_lock do
sleep 2
message ||= "thread 1"
end
end
thread do
sleep 1
lock.with_write_lock do
message ||= "thread 2"
end
end
sleep 3
lock.with_read_lock do
message
end
`

expected := "thread 1"

v := initTestVM()
evaluated := v.testEval(t, code, getFilename())
testStringObject(t, i, evaluated, expected)
v.checkCFP(t, i, 0)
v.checkSP(t, i, 1)
}
74 changes: 0 additions & 74 deletions vm/concurrent_rw_lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,77 +222,3 @@ func TestRWLockWithWriteLockMethod(t *testing.T) {
v.checkCFP(t, i, 0)
v.checkSP(t, i, 1)
}

// Mixed locks (functional tests)

func TestRWLockAcquireAndReleaseLocksReadBlocksWrite(t *testing.T) {
code := `
require 'concurrent/rw_lock'
lock = Concurrent::RWLock.new
message = nil
thread do
lock.acquire_read_lock
sleep 2
message ||= "thread 1"
lock.release_read_lock
end
thread do
sleep 1
lock.acquire_write_lock
message ||= "thread 2"
lock.release_write_lock
end
sleep 3
lock.with_read_lock do
message
end
`

expected := "thread 1"

v := initTestVM()
evaluated := v.testEval(t, code, getFilename())
testStringObject(t, i, evaluated, expected)
v.checkCFP(t, i, 0)
v.checkSP(t, i, 1)
}

func TestRWLockWithReadLockReadBlocksWrite(t *testing.T) {
code := `
require 'concurrent/rw_lock'
lock = Concurrent::RWLock.new
message = nil
thread do
lock.with_read_lock do
sleep 2
message ||= "thread 1"
end
end
thread do
sleep 1
lock.with_write_lock do
message ||= "thread 2"
end
end
sleep 3
lock.with_read_lock do
message
end
`

expected := "thread 1"

v := initTestVM()
evaluated := v.testEval(t, code, getFilename())
testStringObject(t, i, evaluated, expected)
v.checkCFP(t, i, 0)
v.checkSP(t, i, 1)
}

0 comments on commit 512a44f

Please sign in to comment.