From 1cb36d5116db11ce8cf1c49c8a1603975812d986 Mon Sep 17 00:00:00 2001 From: Pierre Laborde Date: Sun, 7 May 2023 17:21:39 +0200 Subject: [PATCH 1/3] Fix #24 --- Molecule-Tests/MolHomeServicesTest.class.st | 36 ++++++++++++--------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/Molecule-Tests/MolHomeServicesTest.class.st b/Molecule-Tests/MolHomeServicesTest.class.st index d1f1e1d1..68b6f844 100644 --- a/Molecule-Tests/MolHomeServicesTest.class.st +++ b/Molecule-Tests/MolHomeServicesTest.class.st @@ -532,31 +532,36 @@ MolHomeServicesTest >> testSubComponentLifecycleWithName [ { #category : #'tests - threading' } MolHomeServicesTest >> testThreadsToStartAndStopComponents [ - | manager nb | + | manager nb random forkList | 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:[(Delay forMilliseconds: 50) 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:[(Delay forMilliseconds: 50) wait]. self assert: manager homeServices deployedComponents size equals: 1. self assert: (manager homeServices deployedComponents at: MolCompleteComponentImpl) isEmpty. @@ -565,20 +570,21 @@ MolHomeServicesTest >> testThreadsToStartAndStopComponents [ { #category : #'tests - threading' } MolHomeServicesTest >> testThreadsToStartAndStopComponents2 [ - | nb oc | + | nb forkList | 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:[(Delay forMilliseconds: 50) wait]. self assert: MolComponentManager default homeServices deployedComponents size equals: 1. self assert: (MolComponentManager default homeServices deployedComponents at: MolCompleteComponentImpl) isEmpty. From 7cbfea080407ea2241669f9610862cc839b9f26b Mon Sep 17 00:00:00 2001 From: Pierre Laborde Date: Sun, 7 May 2023 17:55:52 +0200 Subject: [PATCH 2/3] Fix decompiled source code method Ignore threaded tests for CI --- Molecule-Tests/MolHomeServicesTest.class.st | 16 +++- Molecule/MolHomeServices.class.st | 99 ++++++++++----------- 2 files changed, 62 insertions(+), 53 deletions(-) diff --git a/Molecule-Tests/MolHomeServicesTest.class.st b/Molecule-Tests/MolHomeServicesTest.class.st index 68b6f844..5fcd38d7 100644 --- a/Molecule-Tests/MolHomeServicesTest.class.st +++ b/Molecule-Tests/MolHomeServicesTest.class.st @@ -533,6 +533,11 @@ MolHomeServicesTest >> testSubComponentLifecycleWithName [ MolHomeServicesTest >> testThreadsToStartAndStopComponents [ | manager nb random forkList | + + self timeLimit: 1 second. + "By pass CI" + self skipOnPharoCITestingEnvironment. + manager := MolComponentManager default. nb := 500. random := Random new. @@ -547,7 +552,7 @@ MolHomeServicesTest >> testThreadsToStartAndStopComponents [ ] forkAt: Processor userBackgroundPriority named: ('Molecule test fork ', nb printString)). ]. - [ (forkList detect:[ :f | f isTerminated not] ifNone:[nil]) notNil ] whileTrue:[(Delay forMilliseconds: 50) 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. @@ -561,7 +566,7 @@ MolHomeServicesTest >> testThreadsToStartAndStopComponents [ ] forkAt: Processor userBackgroundPriority named: ('Molecule test fork ', nb printString)). ]. - [ (forkList detect:[ :f | f isTerminated not] ifNone:[nil]) notNil ] whileTrue:[(Delay forMilliseconds: 50) 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. @@ -571,6 +576,11 @@ MolHomeServicesTest >> testThreadsToStartAndStopComponents [ MolHomeServicesTest >> testThreadsToStartAndStopComponents2 [ | nb forkList | + + self timeLimit: 1 second. + "By pass CI" + self skipOnPharoCITestingEnvironment. + nb := 500. forkList := OrderedCollection new. @@ -584,7 +594,7 @@ MolHomeServicesTest >> testThreadsToStartAndStopComponents2 [ ] forkAt: Processor userBackgroundPriority named: ('Molecule test fork ', i printString)). ]. - [ (forkList detect:[ :f | f isTerminated not] ifNone:[nil]) notNil ] whileTrue:[(Delay forMilliseconds: 50) 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. diff --git a/Molecule/MolHomeServices.class.st b/Molecule/MolHomeServices.class.st index cd2119fe..0be10dd8 100644 --- a/Molecule/MolHomeServices.class.st +++ b/Molecule/MolHomeServices.class.st @@ -68,56 +68,55 @@ MolHomeServices >> addDeployedComponent: aComponentClass [ ] { #category : #private } -MolHomeServices >> checkInstanciationOfComponent: arg1 named: arg2 [ - - | tmp1 tmp2 tmp3 | - arg2 ifNil: [ - ^ WrongComponentNameError new messageText: - 'Can not instanciate a component without name' ]. - arg2 isSymbol ifFalse: [ - ^ WrongComponentNameError new messageText: - 'Can not instanciate a component with a name wish is not a symbol' ]. - tmp1 := self deployedComponents at: arg1 ifAbsent: [ - ^ ComponentNotDeployedError new messageText: - 'Can not instanciate a non deployed component' ]. - tmp1 at: arg2 ifPresent: [ :arg3 | - arg3 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: [ - ^ 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 | - (MolComponentManager default locatorServices - searchServicesProviderFor: arg4 - named: arg2) 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 | - (MolComponentManager default locatorServices - searchParametersProviderFor: arg5 - named: arg2) 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 | - (MolComponentManager default locatorServices - searchServicesProviderFor: arg7 - named: arg2) 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 | - (MolComponentManager default locatorServices - searchParametersProviderFor: arg8 - named: arg2) 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 +MolHomeServices >> checkInstanciationOfComponent: aComponentClass named: aName [ + | deployed component | + + "check if the component can be instanciate" + deployed := self deployedComponents at: aComponentClass ifAbsent:[ + ^ComponentNotDeployedError new messageText: 'Can not instanciate a non deployed component'. + ]. + + "check if a component instance with the same name is already exists" + deployed at: aName ifPresent:[ :c | c ifNotNil:[ + ^ComponentAlreadyExistsError new messageText: 'Can not instanciate a component with the same name of another component, please change the name of the component'. + ]]. + + "check if a component with the same type is not already existing with the same name" + component := MolComponentManager default locatorServices searchComponentTypeImplementorFor: aComponentClass componentType named: aName. + 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'. + ]. + + "check if a component with the same services or parameters interface is not already existing with the same name" + aComponentClass componentType allProvidedServices do:[ :e | + (MolComponentManager default locatorServices searchServicesProviderFor: e named: aName) 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'. + ]. + ]. + aComponentClass componentType allProvidedParameters do:[ :e | + (MolComponentManager default locatorServices searchParametersProviderFor: e named: aName) 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'. + ]. + ]. + + "check if the component override an instanciate component type with the same name, in this case the system cannot determine what services/parameters to use and it is necessary to instanciate the component with an another name" + aComponentClass isOverrideComponentType ifTrue:[ | overridedTypes | + overridedTypes := aComponentClass overridedComponentTypes. + overridedTypes do:[ :type | + type allProvidedServices do:[ :e | + (MolComponentManager default locatorServices searchServicesProviderFor: e named: aName) 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'. + ]. + ]. + type allProvidedParameters do:[ :e | + (MolComponentManager default locatorServices searchParametersProviderFor: e named: aName) 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 ] { #category : #accessing } From a977c82b04a3f779bd62f53188c536aecfc0087d Mon Sep 17 00:00:00 2001 From: Pierre Laborde Date: Sun, 7 May 2023 18:02:57 +0200 Subject: [PATCH 3/3] Method copy problem --- Molecule/MolHomeServices.class.st | 101 ++++++++++++++++-------------- 1 file changed, 54 insertions(+), 47 deletions(-) diff --git a/Molecule/MolHomeServices.class.st b/Molecule/MolHomeServices.class.st index 0be10dd8..95d408ab 100644 --- a/Molecule/MolHomeServices.class.st +++ b/Molecule/MolHomeServices.class.st @@ -68,55 +68,62 @@ MolHomeServices >> addDeployedComponent: aComponentClass [ ] { #category : #private } -MolHomeServices >> checkInstanciationOfComponent: aComponentClass named: aName [ - | deployed component | - - "check if the component can be instanciate" - deployed := self deployedComponents at: aComponentClass ifAbsent:[ - ^ComponentNotDeployedError new messageText: 'Can not instanciate a non deployed component'. - ]. - - "check if a component instance with the same name is already exists" - deployed at: aName ifPresent:[ :c | c ifNotNil:[ - ^ComponentAlreadyExistsError new messageText: 'Can not instanciate a component with the same name of another component, please change the name of the component'. - ]]. - - "check if a component with the same type is not already existing with the same name" - component := MolComponentManager default locatorServices searchComponentTypeImplementorFor: aComponentClass componentType named: aName. - 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'. - ]. - - "check if a component with the same services or parameters interface is not already existing with the same name" - aComponentClass componentType allProvidedServices do:[ :e | - (MolComponentManager default locatorServices searchServicesProviderFor: e named: aName) 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'. - ]. - ]. - aComponentClass componentType allProvidedParameters do:[ :e | - (MolComponentManager default locatorServices searchParametersProviderFor: e named: aName) 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'. - ]. - ]. +MolHomeServices >> checkInstanciationOfComponent: aComponentClass named: aComponentName [ - "check if the component override an instanciate component type with the same name, in this case the system cannot determine what services/parameters to use and it is necessary to instanciate the component with an another name" - aComponentClass isOverrideComponentType ifTrue:[ | overridedTypes | + | deployed component overridedTypes | + aComponentName ifNil: [ + ^ WrongComponentNameError new messageText: + 'Can not instanciate a component without name' ]. + + aComponentName isSymbol ifFalse: [ + ^ WrongComponentNameError new messageText: + 'Can not instanciate a component with a name wish is not a symbol' ]. + + deployed := self deployedComponents at: aComponentClass ifAbsent: [ + ^ ComponentNotDeployedError new messageText: + 'Can not instanciate a non deployed component' ]. + 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' ] ]. + + 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' ]. + + aComponentClass componentType allProvidedServices do: [ :e | + (MolComponentManager default locatorServices + 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' ] ]. + + aComponentClass componentType allProvidedParameters do: [ :e | + (MolComponentManager default locatorServices + 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' ] ]. + + aComponentClass isOverrideComponentType ifTrue: [ overridedTypes := aComponentClass overridedComponentTypes. - overridedTypes do:[ :type | - type allProvidedServices do:[ :e | - (MolComponentManager default locatorServices searchServicesProviderFor: e named: aName) 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'. - ]. - ]. - type allProvidedParameters do:[ :e | - (MolComponentManager default locatorServices searchParametersProviderFor: e named: aName) 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 + overridedTypes do: [ :type | + type allProvidedServices do: [ :e | + (MolComponentManager default locatorServices + 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' ] ]. + type allProvidedParameters do: [ :e | + (MolComponentManager default locatorServices + 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 ] { #category : #accessing }