Skip to content

Commit

Permalink
Merge pull request #78 from OpenSmock/dev
Browse files Browse the repository at this point in the history
Fix #24
  • Loading branch information
labordep authored May 7, 2023
2 parents 5adc19f + a977c82 commit 9a17d56
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 41 deletions.
46 changes: 31 additions & 15 deletions Molecule-Tests/MolHomeServicesTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -532,31 +532,41 @@ MolHomeServicesTest >> testSubComponentLifecycleWithName [
{ #category : #'tests - threading' }
MolHomeServicesTest >> testThreadsToStartAndStopComponents [

| manager nb |
| manager nb random forkList |

self timeLimit: 1 second.
"By pass CI"
self skipOnPharoCITestingEnvironment.

manager := MolComponentManager default.
nb := 500.
random := Random new.
forkList := OrderedCollection new.

1 to: nb do:[ :i |
[
(Delay forMilliseconds: (Random new next * 10)) wait.
forkList add: ([
(Delay forMilliseconds: (random next * 10)) wait.
manager deploymentServices deployComponentImplementation: MolCompleteComponentImpl.
manager homeServices instanciateComponent: MolCompleteComponentImpl named: (#key, i printString) asSymbol.
manager homeServices activateComponent: MolCompleteComponentImpl named: (#key, i printString) asSymbol.
] fork.
] forkAt: Processor userBackgroundPriority named: ('Molecule test fork ', nb printString)).
].
(Delay forSeconds: 2) wait.

[ (forkList detect:[ :f | f isTerminated not] ifNone:[nil]) notNil ] whileTrue:[ 50 milliSeconds wait ].
forkList := OrderedCollection new.

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

1 to: nb do:[ :i |
[
(Delay forMilliseconds: (Random new next * 10)) wait.
forkList add: ([
(Delay forMilliseconds: (random next * 10)) wait.
manager homeServices passivateComponent: MolCompleteComponentImpl named: (#key, i printString) asSymbol.
manager homeServices removeComponent: MolCompleteComponentImpl named: (#key, i printString) asSymbol.
] fork.
] forkAt: Processor userBackgroundPriority named: ('Molecule test fork ', nb printString)).
].
(Delay forSeconds: 2) wait.

[ (forkList detect:[ :f | f isTerminated not] ifNone:[nil]) notNil ] whileTrue:[ 50 milliSeconds wait ].

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

| nb oc |
| nb forkList |

self timeLimit: 1 second.
"By pass CI"
self skipOnPharoCITestingEnvironment.

nb := 500.
oc := OrderedCollection new.
forkList := OrderedCollection new.

1 to: nb do:[ :i |
oc add: [
forkList add: ([
MolComponentManager default deploymentServices deployComponentImplementation: MolCompleteComponentImpl.
MolComponentManager default homeServices instanciateComponent: MolCompleteComponentImpl named: (#key, i printString) asSymbol.
MolComponentManager default homeServices activateComponent: MolCompleteComponentImpl named: (#key, i printString) asSymbol.
MolComponentManager default homeServices passivateComponent: MolCompleteComponentImpl named: (#key, i printString) asSymbol.
MolComponentManager default homeServices removeComponent: MolCompleteComponentImpl named: (#key, i printString) asSymbol.
].
] forkAt: Processor userBackgroundPriority named: ('Molecule test fork ', i printString)).
].
oc do:[ :bloc | bloc fork ].
(Delay forSeconds: 1) wait.

[ (forkList detect:[ :f | f isTerminated not] ifNone:[nil]) notNil ] whileTrue:[ 50 milliSeconds wait ].

self assert: MolComponentManager default homeServices deployedComponents size equals: 1.
self assert: (MolComponentManager default homeServices deployedComponents at: MolCompleteComponentImpl) isEmpty.
Expand Down
58 changes: 32 additions & 26 deletions Molecule/MolHomeServices.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -68,53 +68,59 @@ MolHomeServices >> addDeployedComponent: aComponentClass [
]

{ #category : #private }
MolHomeServices >> checkInstanciationOfComponent: arg1 named: arg2 [
MolHomeServices >> checkInstanciationOfComponent: aComponentClass named: aComponentName [

| tmp1 tmp2 tmp3 |
arg2 ifNil: [
| deployed component overridedTypes |
aComponentName ifNil: [
^ WrongComponentNameError new messageText:
'Can not instanciate a component without name' ].
arg2 isSymbol ifFalse: [

aComponentName isSymbol ifFalse: [
^ WrongComponentNameError new messageText:
'Can not instanciate a component with a name wish is not a symbol' ].
tmp1 := self deployedComponents at: arg1 ifAbsent: [

deployed := self deployedComponents at: aComponentClass ifAbsent: [
^ ComponentNotDeployedError new messageText:
'Can not instanciate a non deployed component' ].
tmp1 at: arg2 ifPresent: [ :arg3 |
arg3 ifNotNil: [
deployed at: aComponentName ifPresent: [ :e |
e ifNotNil: [
^ ComponentAlreadyExistsError new messageText:
'Can not instanciate a component with the same name of another component, please change the name of the component' ] ].
tmp2 := MolComponentManager default locatorServices
searchComponentTypeImplementorFor: arg1 componentType
named: arg2.
tmp2 ifNotNil: [

component := MolComponentManager default locatorServices
searchComponentTypeImplementorFor: aComponentClass componentType
named: aComponentName.
component ifNotNil: [
^ ComponentAlreadyExistsError new messageText:
'Can not instanciate a component with the same type and name of another component, please change the name of the component' ].
arg1 componentType allProvidedServices do: [ :arg4 |

aComponentClass componentType allProvidedServices do: [ :e |
(MolComponentManager default locatorServices
searchServicesProviderFor: arg4
named: arg2) isNotFoundServices ifFalse: [
searchServicesProviderFor: e
named: aComponentName) isNotFoundServices ifFalse: [
^ ComponentProvidedServicesAlreadyExistsError new messageText:
'Can not instanciate a component with the same services and name of another component, please change the name of the component' ] ].
arg1 componentType allProvidedParameters do: [ :arg5 |

aComponentClass componentType allProvidedParameters do: [ :e |
(MolComponentManager default locatorServices
searchParametersProviderFor: arg5
named: arg2) isNotFoundParameters ifFalse: [
searchParametersProviderFor: e
named: aComponentName) isNotFoundParameters ifFalse: [
^ ComponentProvidedParametersAlreadyExistsError new messageText:
'Can not instanciate a component with the same parameters and name of another component, please change the name of the component' ] ].
arg1 isOverrideComponentType ifTrue: [
tmp3 := arg1 overridedComponentTypes.
tmp3 do: [ :arg6 |
arg6 allProvidedServices do: [ :arg7 |

aComponentClass isOverrideComponentType ifTrue: [
overridedTypes := aComponentClass overridedComponentTypes.
overridedTypes do: [ :type |
type allProvidedServices do: [ :e |
(MolComponentManager default locatorServices
searchServicesProviderFor: arg7
named: arg2) isNotFoundServices ifFalse: [
searchServicesProviderFor: e
named: aComponentName) isNotFoundServices ifFalse: [
^ ComponentProvidedServicesAlreadyExistsError new messageText:
'(Inheritance problem) Can not instanciate a component with the same services and name of another component, please change the name of the component' ] ].
arg6 allProvidedParameters do: [ :arg8 |
type allProvidedParameters do: [ :e |
(MolComponentManager default locatorServices
searchParametersProviderFor: arg8
named: arg2) isNotFoundParameters ifFalse: [
searchParametersProviderFor: e
named: aComponentName) isNotFoundParameters ifFalse: [
^ ComponentProvidedServicesAlreadyExistsError new messageText:
'(Inheritance problem) Can not instanciate a component with the same parameters and name of another component, please change the name of the component' ] ] ] ].
^ nil
Expand Down

0 comments on commit 9a17d56

Please sign in to comment.