'From Squeak3.2gamma of 15 January 2002 [latest update: #4889] on 1 July 2002 at 11:14:30 pm'! TestCase subclass: #MonitorTest instanceVariableNames: 'm out ' classVariableNames: '' poolDictionaries: '' category: 'Kernel-Processes'! !MonitorTest methodsFor: 'Testing' stamp: 'NS 7/1/2002 20:02'! testDefaultQueue1 10 timesRepeat: [[m critical: [m wait. out add: 1]] forkAt: Processor userInterruptPriority]. self assert: out isEmpty. 1 to: 10 do: [:index | m critical: [m signal]. self assert: out size = index]. self assert: out size = 10! ! !MonitorTest methodsFor: 'Testing' stamp: 'NS 7/1/2002 20:02'! testDefaultQueue2 10 timesRepeat: [[m critical: [m wait. out add: 1]] forkAt: Processor userInterruptPriority]. self assert: out isEmpty. m critical: [m signalAll]. self assert: out size = 10! ! !MonitorTest methodsFor: 'Testing' stamp: 'NS 7/1/2002 20:02'! testDefaultQueue3 10 timesRepeat: [[m critical: [m wait. out add: 1]] forkAt: Processor userInterruptPriority]. self assert: out isEmpty. 1 to: 10 do: [:index | m critical: [m signal: ('a', index asString) asSymbol]. self assert: out size = index]. self assert: out size = 10.! ! !MonitorTest methodsFor: 'Testing' stamp: 'NS 7/1/2002 20:02'! testDefaultQueueUntil1 | a | a _ ValueHolder new contents: 0. 3 timesRepeat: [ [m critical: [ m waitUntil: [a contents > 10]. out add: a contents. a contents: 0]] forkAt: Processor userInterruptPriority]. self assert: out isEmpty. a contents: 11. self assert: out isEmpty. m critical: [m signal]. self assert: (out size = 1 and: [out last = 11]). m critical: [m signal]. self assert: out size = 1. a contents: 12. self assert: out size = 1. m critical: [m signal. Processor yield. a contents: 13. m signal]. self assert: (out size = 2 and: [out last = 13]). m critical: [a contents: 14. m signal]. self assert: (out size = 3 and: [out last = 14])! ! !MonitorTest methodsFor: 'Testing' stamp: 'NS 7/1/2002 20:02'! testDefaultQueueUntilWithTimeout1 | a | a _ ValueHolder new contents: 0. [m critical: [m waitUntil: [a contents > 10]. out add: 1]] forkAt: Processor userInterruptPriority. [m critical: [m waitUntil: [a contents > 20] maxMilliseconds: 10. out add: 2]] forkAt: Processor userInterruptPriority. m critical: [m signal]. a contents: 15. self assert: out isEmpty. (Delay forMilliseconds: 11) wait. self assert: out isEmpty. m critical: [m signal]. a contents: 22. self assert: (out size = 1 and: [out last = 1]). (Delay forMilliseconds: 11) wait. self assert: (out size = 2 and: [out last = 2]).! ! !MonitorTest methodsFor: 'Testing' stamp: 'NS 7/1/2002 20:02'! testDefaultQueueWithTimeout1 [m critical: [m wait. out add: 1]] forkAt: Processor userInterruptPriority. [m critical: [m waitMaxMilliseconds: 10. out add: 2]] forkAt: Processor userInterruptPriority. [m critical: [m wait. out add: 3]] forkAt: Processor userInterruptPriority. [m critical: [m waitMaxMilliseconds: 30. out add: 4]] forkAt: Processor userInterruptPriority. [m critical: [m waitMaxMilliseconds: 20. out add: 5]] forkAt: Processor userInterruptPriority. [m critical: [m waitMaxSeconds: 1. out add: 6]] forkAt: Processor userInterruptPriority. self assert: out isEmpty. (Delay forMilliseconds: 11) wait. self assert: (out size = 1 and: [out last = 2]). (Delay forMilliseconds: 11) wait. self assert: (out size = 2 and: [out last = 5]). (Delay forMilliseconds: 11) wait. self assert: (out size = 3 and: [out last = 4]). m critical: [m signal]. self assert: (out size = 4 and: [out last = 1]). m critical: [m signal]. self assert: (out size = 5 and: [out last = 3]). m critical: [m signal]. self assert: (out size = 6 and: [out last = 6]). ! ! !MonitorTest methodsFor: 'Testing' stamp: 'NS 7/1/2002 20:03'! testQueue1 10 timesRepeat: [ [m critical: [m waitFor: #event. out add: 2]] forkAt: Processor userInterruptPriority. [m critical: [m wait. out add: 1]] forkAt: Processor userInterruptPriority]. self assert: out isEmpty. 1 to: 10 do: [:index | m critical: [m signal]. self assert: out size = index]. 1 to: 10 do: [:index | m critical: [m signal: #event]. self assert: out size = (10 + index)]. 1 to: 20 do: [:index | index <= 10 ifTrue: [self assert: (out at: index) = 1] ifFalse: [self assert: (out at: index) = 2]].! ! !MonitorTest methodsFor: 'Running' stamp: 'NS 7/1/2002 16:36'! setUp m _ Monitor new. out _ OrderedCollection new.! ! MonitorTest removeSelector: #testDefaultQueue4! MonitorTest removeSelector: #testDefaultQueueBasic! MonitorTest removeSelector: #testDefaultQueueUntilWithTimeout! MonitorTest removeSelector: #testDefaultQueueWithTimeout! MonitorTest removeSelector: #testTest! !MonitorTest reorganize! ('Testing' testDefaultQueue1 testDefaultQueue2 testDefaultQueue3 testDefaultQueueUntil1 testDefaultQueueUntilWithTimeout1 testDefaultQueueWithTimeout1 testQueue1) ('Running' setUp) !