'From Squeak5.3alpha of 22 March 2019 [latest update: #18478] on 18 April 2019 at 2:36:48 pm'!
TestCase subclass: #ProcessSpecificTest
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'KernelTests-Processes'!
!ProcessSpecificTest commentStamp: 'mvl 3/13/2007 13:52' prior: 0!
A ProcessSpecificTest is a test case for process local and dynamic variables.
!


!ProcessSpecificTest methodsFor: 'tests' stamp: 'ul 9/17/2011 17:48'!
testAssignmentToLocalVariableReturnsTheValue

	self assert: 1 equals: (TestLocalVariable value: 1)! !

!ProcessSpecificTest methodsFor: 'tests' stamp: 'mvl 3/13/2007 15:02'!
testDynamicVariable

	| s1 s2 p1stopped p2stopped |
	s1 := Semaphore new.
	s2 := Semaphore new.
	p1stopped := p2stopped := false.
	[
		TestDynamicVariable value: 1 during:[
			self checkDynamic: 1.
			(Delay forMilliseconds: 30) wait.
			self checkDynamic: 1.
			TestDynamicVariable value: 3 during:[
				(Delay forMilliseconds: 30) wait.
				self checkDynamic: 3
			].
			self checkDynamic: 1.
		].
		self checkDynamic: nil.
		p1stopped := true.
		s1 signal.
	] fork.

	[
		TestDynamicVariable value: 2 during:[
			self checkDynamic: 2.
			(Delay forMilliseconds: 30) wait.
			self checkDynamic: 2.
		].
		self checkDynamic: nil.
		p2stopped := true.
		s2 signal.
	] fork.

	"Set a maximum wait timeout so that the test case will complete 
	 even if the processes fail to signal us."
	s1 waitTimeoutSeconds: 2.
	s2 waitTimeoutSeconds: 2.
	self assert: p1stopped.
	self assert: p2stopped.! !

!ProcessSpecificTest methodsFor: 'tests' stamp: 'mt 1/31/2015 18:11'!
testDynamicVariableDefault

	"Just double-check our fixture."
	TestDynamicVariable default: #default.
	self assert: #default equals: TestDynamicVariable default.

	"Now check for default lookup out of any dynamic scope."
	self checkDynamic: #default..

	"Ignore default value by setting dynamic scope."
	TestDynamicVariable value: #dynamic during: [
		self checkDynamic: #dynamic].

	"Out of that scope, we should fall back to the default again."
	self checkDynamic: #default.

	"...even if that default value changes."
	TestDynamicVariable default: #anotherDefault.
	self checkDynamic: #anotherDefault.
! !

!ProcessSpecificTest methodsFor: 'tests' stamp: 'mvl 3/13/2007 15:03'!
testLocalVariable

	| s1 s2 p1stopped p2stopped |
	s1 := Semaphore new.
	s2 := Semaphore new.
	p1stopped := p2stopped := false.
	[
		self checkLocal: 0.
		TestLocalVariable value: 1.
		self checkLocal: 1.
		(Delay forMilliseconds: 30) wait.
		self checkLocal: 1.
		TestLocalVariable value: 2.
		self checkLocal: 2.
		p1stopped := true.
		s1 signal.
	] fork.

	[
		(Delay forMilliseconds: 30) wait.
		self checkLocal: 0.
		TestLocalVariable value: 3.
		self checkLocal: 3.
		(Delay forMilliseconds: 30) wait.
		self checkLocal: 3.
		TestLocalVariable value: 4.
		self checkLocal: 4.
		p2stopped := true.
		s2 signal.
	] fork.

	"Set a maximum wait timeout so that the test case will complete 
	 even if the processes fail to signal us."
	s1 waitTimeoutMSecs: 5000.
	s2 waitTimeoutMSecs: 5000.
	self assert: p1stopped.
	self assert: p2stopped.
! !

!ProcessSpecificTest methodsFor: 'tests' stamp: 'mt 4/18/2019 14:35'!
testOuterScopeAccess

	TestDynamicVariable value: 1 during: [
		TestDynamicVariable value: 2 during: [
			TestDynamicVariable value: 3 during: [
				self assert: (#(3 2 1) hasEqualElements: TestDynamicVariable scope withAllValues)].
			self assert: (#(2 1) hasEqualElements: TestDynamicVariable scope withAllValues)].
		self assert: (#(1) hasEqualElements: TestDynamicVariable scope withAllValues)].!
]style[(20 23 6 1 1 1 7 25 6 1 1 1 7 1 1 24 6 1 1 1 7 1 1 5 4 1 7 1 1 1 1 1 1 1 1 1 2 17 21 5 1 13 1 1 5 4 1 7 1 1 1 1 1 1 1 2 17 21 5 1 13 1 1 4 4 1 7 1 1 1 1 1 2 17 21 5 1 13 1 2)b,cblack;,c000000126,cblack;,c126000000,cblack;,c000000126,cblack;,c000000126,cblack;,c126000000,cblack;,c000000126,cblack;,c000126000,cblack;,c000000126,cblack;,c126000000,cblack;,c000000126,cblack;,c126000126,cblack;,c126000000,cblack;,c000000126,cblack;,c126000000,c000000126,cblack;,c126000000,cblack;,c126000000,cblack;,c126000000,cblack;,c000000126,cblack;,c000000126,cblack;,c000000126,c126000000,c126000126,cblack;,c126000000,cblack;,c000000126,cblack;,c126000126,c000000126,cblack;,c126000000,cblack;,c126000000,cblack;,c000000126,cblack;,c000000126,cblack;,c000000126,c126000126,c000126000,cblack;,c126000000,cblack;,c000000126,cblack;,c000126000,c000000126,cblack;,c126000000,cblack;,c000000126,cblack;,c000000126,cblack;,c000000126,c000126000,cblack;! !


!ProcessSpecificTest methodsFor: 'running' stamp: 'mt 1/31/2015 18:09'!
tearDown
	"Make sure we don't pollute the running process' environment with the test variables"

	{ TestLocalVariable. TestDynamicVariable } do: [ :each |
		Processor activeProcess environmentRemoveKey: each ifAbsent: [] ].

	TestDynamicVariable default: nil.! !


!ProcessSpecificTest methodsFor: 'support' stamp: 'mt 1/31/2015 18:06'!
checkDynamic: value

	self assert: value equals: TestDynamicVariable value.! !

!ProcessSpecificTest methodsFor: 'support' stamp: 'mt 1/31/2015 18:06'!
checkLocal: value

	self assert: value equals: TestLocalVariable value.! !
