Skip to content

Commit 9a17d56

Browse files
authored
Merge pull request #78 from OpenSmock/dev
Fix #24
2 parents 5adc19f + a977c82 commit 9a17d56

File tree

2 files changed

+63
-41
lines changed

2 files changed

+63
-41
lines changed

Molecule-Tests/MolHomeServicesTest.class.st

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -532,31 +532,41 @@ MolHomeServicesTest >> testSubComponentLifecycleWithName [
532532
{ #category : #'tests - threading' }
533533
MolHomeServicesTest >> testThreadsToStartAndStopComponents [
534534

535-
| manager nb |
535+
| manager nb random forkList |
536+
537+
self timeLimit: 1 second.
538+
"By pass CI"
539+
self skipOnPharoCITestingEnvironment.
540+
536541
manager := MolComponentManager default.
537542
nb := 500.
543+
random := Random new.
544+
forkList := OrderedCollection new.
538545

539546
1 to: nb do:[ :i |
540-
[
541-
(Delay forMilliseconds: (Random new next * 10)) wait.
547+
forkList add: ([
548+
(Delay forMilliseconds: (random next * 10)) wait.
542549
manager deploymentServices deployComponentImplementation: MolCompleteComponentImpl.
543550
manager homeServices instanciateComponent: MolCompleteComponentImpl named: (#key, i printString) asSymbol.
544551
manager homeServices activateComponent: MolCompleteComponentImpl named: (#key, i printString) asSymbol.
545-
] fork.
552+
] forkAt: Processor userBackgroundPriority named: ('Molecule test fork ', nb printString)).
546553
].
547-
(Delay forSeconds: 2) wait.
554+
555+
[ (forkList detect:[ :f | f isTerminated not] ifNone:[nil]) notNil ] whileTrue:[ 50 milliSeconds wait ].
556+
forkList := OrderedCollection new.
548557

549558
self assert: manager homeServices deployedComponents size equals: 1.
550559
self assert: (manager homeServices deployedComponents at: MolCompleteComponentImpl) size equals: nb.
551560

552561
1 to: nb do:[ :i |
553-
[
554-
(Delay forMilliseconds: (Random new next * 10)) wait.
562+
forkList add: ([
563+
(Delay forMilliseconds: (random next * 10)) wait.
555564
manager homeServices passivateComponent: MolCompleteComponentImpl named: (#key, i printString) asSymbol.
556565
manager homeServices removeComponent: MolCompleteComponentImpl named: (#key, i printString) asSymbol.
557-
] fork.
566+
] forkAt: Processor userBackgroundPriority named: ('Molecule test fork ', nb printString)).
558567
].
559-
(Delay forSeconds: 2) wait.
568+
569+
[ (forkList detect:[ :f | f isTerminated not] ifNone:[nil]) notNil ] whileTrue:[ 50 milliSeconds wait ].
560570

561571
self assert: manager homeServices deployedComponents size equals: 1.
562572
self assert: (manager homeServices deployedComponents at: MolCompleteComponentImpl) isEmpty.
@@ -565,20 +575,26 @@ MolHomeServicesTest >> testThreadsToStartAndStopComponents [
565575
{ #category : #'tests - threading' }
566576
MolHomeServicesTest >> testThreadsToStartAndStopComponents2 [
567577

568-
| nb oc |
578+
| nb forkList |
579+
580+
self timeLimit: 1 second.
581+
"By pass CI"
582+
self skipOnPharoCITestingEnvironment.
583+
569584
nb := 500.
570-
oc := OrderedCollection new.
585+
forkList := OrderedCollection new.
586+
571587
1 to: nb do:[ :i |
572-
oc add: [
588+
forkList add: ([
573589
MolComponentManager default deploymentServices deployComponentImplementation: MolCompleteComponentImpl.
574590
MolComponentManager default homeServices instanciateComponent: MolCompleteComponentImpl named: (#key, i printString) asSymbol.
575591
MolComponentManager default homeServices activateComponent: MolCompleteComponentImpl named: (#key, i printString) asSymbol.
576592
MolComponentManager default homeServices passivateComponent: MolCompleteComponentImpl named: (#key, i printString) asSymbol.
577593
MolComponentManager default homeServices removeComponent: MolCompleteComponentImpl named: (#key, i printString) asSymbol.
578-
].
594+
] forkAt: Processor userBackgroundPriority named: ('Molecule test fork ', i printString)).
579595
].
580-
oc do:[ :bloc | bloc fork ].
581-
(Delay forSeconds: 1) wait.
596+
597+
[ (forkList detect:[ :f | f isTerminated not] ifNone:[nil]) notNil ] whileTrue:[ 50 milliSeconds wait ].
582598

583599
self assert: MolComponentManager default homeServices deployedComponents size equals: 1.
584600
self assert: (MolComponentManager default homeServices deployedComponents at: MolCompleteComponentImpl) isEmpty.

Molecule/MolHomeServices.class.st

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -68,53 +68,59 @@ MolHomeServices >> addDeployedComponent: aComponentClass [
6868
]
6969

7070
{ #category : #private }
71-
MolHomeServices >> checkInstanciationOfComponent: arg1 named: arg2 [
71+
MolHomeServices >> checkInstanciationOfComponent: aComponentClass named: aComponentName [
7272

73-
| tmp1 tmp2 tmp3 |
74-
arg2 ifNil: [
73+
| deployed component overridedTypes |
74+
aComponentName ifNil: [
7575
^ WrongComponentNameError new messageText:
7676
'Can not instanciate a component without name' ].
77-
arg2 isSymbol ifFalse: [
77+
78+
aComponentName isSymbol ifFalse: [
7879
^ WrongComponentNameError new messageText:
7980
'Can not instanciate a component with a name wish is not a symbol' ].
80-
tmp1 := self deployedComponents at: arg1 ifAbsent: [
81+
82+
deployed := self deployedComponents at: aComponentClass ifAbsent: [
8183
^ ComponentNotDeployedError new messageText:
8284
'Can not instanciate a non deployed component' ].
83-
tmp1 at: arg2 ifPresent: [ :arg3 |
84-
arg3 ifNotNil: [
85+
deployed at: aComponentName ifPresent: [ :e |
86+
e ifNotNil: [
8587
^ ComponentAlreadyExistsError new messageText:
8688
'Can not instanciate a component with the same name of another component, please change the name of the component' ] ].
87-
tmp2 := MolComponentManager default locatorServices
88-
searchComponentTypeImplementorFor: arg1 componentType
89-
named: arg2.
90-
tmp2 ifNotNil: [
89+
90+
component := MolComponentManager default locatorServices
91+
searchComponentTypeImplementorFor: aComponentClass componentType
92+
named: aComponentName.
93+
component ifNotNil: [
9194
^ ComponentAlreadyExistsError new messageText:
9295
'Can not instanciate a component with the same type and name of another component, please change the name of the component' ].
93-
arg1 componentType allProvidedServices do: [ :arg4 |
96+
97+
aComponentClass componentType allProvidedServices do: [ :e |
9498
(MolComponentManager default locatorServices
95-
searchServicesProviderFor: arg4
96-
named: arg2) isNotFoundServices ifFalse: [
99+
searchServicesProviderFor: e
100+
named: aComponentName) isNotFoundServices ifFalse: [
97101
^ ComponentProvidedServicesAlreadyExistsError new messageText:
98102
'Can not instanciate a component with the same services and name of another component, please change the name of the component' ] ].
99-
arg1 componentType allProvidedParameters do: [ :arg5 |
103+
104+
aComponentClass componentType allProvidedParameters do: [ :e |
100105
(MolComponentManager default locatorServices
101-
searchParametersProviderFor: arg5
102-
named: arg2) isNotFoundParameters ifFalse: [
106+
searchParametersProviderFor: e
107+
named: aComponentName) isNotFoundParameters ifFalse: [
103108
^ ComponentProvidedParametersAlreadyExistsError new messageText:
104109
'Can not instanciate a component with the same parameters and name of another component, please change the name of the component' ] ].
105-
arg1 isOverrideComponentType ifTrue: [
106-
tmp3 := arg1 overridedComponentTypes.
107-
tmp3 do: [ :arg6 |
108-
arg6 allProvidedServices do: [ :arg7 |
110+
111+
aComponentClass isOverrideComponentType ifTrue: [
112+
overridedTypes := aComponentClass overridedComponentTypes.
113+
overridedTypes do: [ :type |
114+
type allProvidedServices do: [ :e |
109115
(MolComponentManager default locatorServices
110-
searchServicesProviderFor: arg7
111-
named: arg2) isNotFoundServices ifFalse: [
116+
searchServicesProviderFor: e
117+
named: aComponentName) isNotFoundServices ifFalse: [
112118
^ ComponentProvidedServicesAlreadyExistsError new messageText:
113119
'(Inheritance problem) Can not instanciate a component with the same services and name of another component, please change the name of the component' ] ].
114-
arg6 allProvidedParameters do: [ :arg8 |
120+
type allProvidedParameters do: [ :e |
115121
(MolComponentManager default locatorServices
116-
searchParametersProviderFor: arg8
117-
named: arg2) isNotFoundParameters ifFalse: [
122+
searchParametersProviderFor: e
123+
named: aComponentName) isNotFoundParameters ifFalse: [
118124
^ ComponentProvidedServicesAlreadyExistsError new messageText:
119125
'(Inheritance problem) Can not instanciate a component with the same parameters and name of another component, please change the name of the component' ] ] ] ].
120126
^ nil

0 commit comments

Comments
 (0)