﻿'From Squeak6.0alpha of 7 February 2022 [latest update: #21211] on 7 May 2022 at 1:20:48 pm'!

!ProcessTest methodsFor: 'tests' stamp: 'jar 5/7/2022 13:13'!
testResumeTerminatingProcess

	| terminatee terminator resumed semaphore |
	semaphore := Semaphore new.
	terminatee := [semaphore critical:[]. resumed := true] fork.
	Processor yield.
	terminator := [terminatee terminate] newProcess.
	self assert: terminatee suspendingList == semaphore.
	self assert: terminator isSuspended. 
	"run terminator and stop inside #releaseCriticalSection:"
	terminator runUntil: [:ctx | ctx selectorToSendOrSelf = #priority:].
	self assert: terminator isSuspended.
	"resume the terminatee process and and check if the VM raises an error;
	an error is expected because terminatee's suspendedContext equals nil"
	self should: [terminatee resume] raise: Error.
	"now let the terminator finish terminating the terminatee process"
	terminator resume.
	Processor yield.
	self assert: resumed isNil.
	self assert: terminatee isTerminated.
	self assert: terminator isTerminated! !

!ProcessTest methodsFor: 'tests' stamp: 'jar 5/7/2022 13:13'!
testTerminateTerminatingProcess

	| terminatee terminator resumed semaphore |
	semaphore := Semaphore new.
	terminatee := [semaphore critical:[]. resumed := true] fork.
	Processor yield.
	terminator := [terminatee terminate] newProcess.
	self assert: terminatee suspendingList == semaphore.
	self assert: terminator isSuspended. 
	"run terminator and stop inside #releaseCriticalSection:"
	terminator runUntil: [:ctx | ctx selectorToSendOrSelf = #priority:].
	self assert: terminator isSuspended.
	"terminate the terminatee process again and let the termination finish;
	an error is expected because #terminate detected multiple termination"
	self should: [terminatee terminate] raise: Error.
	"now let the terminator finish terminating the terminatee process"
	terminator resume.
	Processor yield.
	self assert: resumed isNil.
	self assert: terminatee isTerminated.
	self assert: terminator isTerminated! !

!ProcessTest methodsFor: 'support' stamp: 'jar 5/7/2022 13:19'!
expectedFailures

	^ #(testTerminateTerminatingProcess testResumeTerminatingProcess)! !

