-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split Concurrent::RWLock
noracedetection
tests into separate file (…
…/build)
- Loading branch information
1 parent
9c6e4af
commit 512a44f
Showing
2 changed files
with
81 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters