'From Cuis 1.0 of 4 September 2009 [latest update: #290] on 22 September 2009 at 8:56:58 am'!
!classDefinition: #DelayTest category: #'Kernel Tests'!
TestCase subclass: #DelayTest
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Kernel Tests'!

!Delay methodsFor: 'private' stamp: 'jmv 9/22/2009 08:13'!
schedule
	"Schedule this delay"
	beingWaitedOn ifTrue: [^self error: 'This Delay has already been scheduled.'].
	resumptionTime := Time millisecondClockValue + delayDuration.
	AccessProtect critical:[
		ScheduledDelay := self.
		TimingSemaphore signal.
	].! !


!DelayTest methodsFor: 'testing-limits' stamp: 'jmv 9/22/2009 08:19'!
testMultiProcessWaitOnSameDelay
	"Ensure that waiting on the same delay from multiple processes raises an error"
	 | delay p1 p2 wasRun |
	delay := Delay forSeconds: 1.
	wasRun := false.
	p1 := [delay wait] newProcess.
	p2 := [
		self should:[delay wait] raise: Error.
		wasRun := true.
	] newProcess.
	p1 resumeAt: Processor activePriority+1.
	p2 resumeAt: Processor activePriority+1.
	p1 terminate.
	p2 terminate.
	self assert: wasRun! !

!DelayTest methodsFor: 'testing-limits' stamp: 'jmv 9/22/2009 08:10'!
testMultiSchedule
         "Ensure that scheduling the same delay twice raises an error"
         | delay |
         delay := Delay forSeconds: 1.
         delay schedule.
         self should:[delay schedule] raise: Error! !


!Process methodsFor: 'changing process state' stamp: 'jmv 9/22/2009 08:18'!
resumeAt: aPriority
	self priority: aPriority.
	^self resume! !


!DelayTest reorganize!
('testing')
('testing-limits' testMultiProcessWaitOnSameDelay testMultiSchedule)
!

