﻿'From Squeak6.1alpha of 28 December 2022 [latest update: #22309] on 1 January 2023 at 9:45:52 am'!

!ProcessTest methodsFor: 'tests' stamp: 'jar 1/1/2023 09:44'!
testResumeTerminatingProcess
	"An attempt to resume a terminating process should probably raise an error;
	leave this test as an expected failure for the moment."

	| terminatee terminator resumed |
	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 #terminate"
	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 1/1/2023 09:43'!
testTerminateTerminatingProcess
	"An attempt to terminate a terminating process should probably raise an error;
	leave this test as an expected failure for the moment."

	| terminatee terminator resumed |
	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 #terminate"
	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! !

