'From Squeak3.10beta of 22 July 2007 [latest update: #7130] on 5 October 2007 at 6:18:14 pm'!
"Change Set:		SemaTests
Date:			5 October 2007
Author:			Andreas Raab

Tests to cover the 'one too many' and the 'one too few' problems with Semaphore."!


!SemaphoreTest methodsFor: 'testing' stamp: 'ar 10/5/2007 18:09'!
testSemaAfterCriticalWait	"self run: #testSemaAfterCriticalWait"
	"This tests whether a semaphore that has just left the wait in Semaphore>>critical:
	leaves it with signaling the associated semaphore."
	| s p |
	s := Semaphore new.
	p := [s critical:[]] forkAt: Processor activePriority-1.
	"wait until p entered the critical section"
	[p suspendingList == s] whileFalse:[(Delay forMilliseconds: 10) wait].
	"Now that p entered it, signal the semaphore. p now 'owns' the semaphore
	but since we are running at higher priority than p it will not get to do
	anything."
	s signal.
	p terminate.
	self assert:[(s instVarNamed: #excessSignals) = 1]! !

!SemaphoreTest methodsFor: 'testing' stamp: 'ar 10/5/2007 18:06'!
testSemaInCriticalWait	"self run: #testSemaInCriticalWait"
	"This tests whether a semaphore that has entered the wait in Semaphore>>critical:
	leaves it without signaling the associated semaphore."
	| s p |
	s := Semaphore new.
	p := [s critical:[]] fork.
	Processor yield.
	self assert:[p suspendingList == s].
	p terminate.
	self assert:[(s instVarNamed: #excessSignals) = 0]! !

