Skip to content

Commit

Permalink
Merge pull request #176 from OpenSmock/dev-issue171
Browse files Browse the repository at this point in the history
  • Loading branch information
labordep authored Apr 3, 2024
2 parents c8b5d0c + c3ed105 commit adcf24e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 59 deletions.
44 changes: 16 additions & 28 deletions src/Molecule-Tests/MolComponentManagerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ Class {

{ #category : #'setUp - tearDown' }
MolComponentManagerTest >> setUp [

super setUp.
MolComponentManager cleanUp
MolComponentManager cleanUp.
Smalltalk garbageCollect.
Smalltalk garbageCollectMost.
]

{ #category : #'setUp - tearDown' }
MolComponentManagerTest >> tearDown [

MolComponentManager cleanUp.
Smalltalk garbageCollect.
Smalltalk garbageCollectMost.
super tearDown
]

Expand Down Expand Up @@ -110,40 +116,22 @@ MolComponentManagerTest >> testDeploymentServices [

{ #category : #tests }
MolComponentManagerTest >> testFlushComponents [

| nb |

"Create some classics components to flush"
1 to: 10 do:[ :i | MolCompleteComponentImpl new ].
"Create some classic components to flush"
1 to: 10 do: [ :i | MolCompleteComponentImpl new ].
"Create some augmented class as components to flush"
1 to: 10 do:[ :i | MolAugmentedClassToAComponent new ].
"Check created instances"
self assert: MolCompleteComponentImpl allInstances size equals: 10.
self assert: MolAugmentedClassToAComponent allInstances size equals: 10.
1 to: 10 do: [ :i | MolAugmentedClassToAComponent new ].

nb := MolComponentManager flushComponents.
self assert: nb equals: 20.
self assert: MolCompleteComponentImpl allInstances size equals: 0.
self assert: MolAugmentedClassToAComponent allInstances size equals: 0.
]

{ #category : #'setUp - tearDown' }
MolComponentManagerTest >> testGarbageCollect [

"Create some classics components to clean"

1 to: 10 do: [ :i |
MolCompleteComponentImpl start: ('test' , i printString) asSymbol ].

"Check created instances"
self assert: MolCompleteComponentImpl allInstances size equals: 10.
self
assert: MolAugmentedClassToAComponent allInstances size
equals: 10.

nb := MolComponentManager flushComponents.

1 to: 10 do: [ :i |
MolCompleteComponentImpl stop: ('test' , i printString) asSymbol ].

Smalltalk garbageCollect.

self assert: MolCompleteComponentImpl allInstances size equals: 0
self assert: nb equals: 20
]

{ #category : #tests }
Expand Down
73 changes: 42 additions & 31 deletions src/Molecule/MolComponentManager.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -59,36 +59,45 @@ MolComponentManager class >> cleanUp: aBoolean [

{ #category : #cleanup }
MolComponentManager class >> deepCleanUp [

<script: 'self deepCleanUp'>
| i j |

"Try to remove non garbaged component instances"
Smalltalk garbageCollect.

Smalltalk garbageCollectMost.

self cleanUp.
MolUtils log: 'Starting a deep cleanUp.'.
MolComponentFactory allInstancesDo: [ :factory | (factory == MolComponentFactory default) ifFalse:[factory release]].
MolComponentFactory allInstancesDo: [ :factory |
factory == MolComponentFactory default ifFalse: [ factory release ] ].
i := self flushComponents.
j := i.

"Try to reflush"
i > 0 ifTrue:[
i > 0 ifTrue: [

Smalltalk garbageCollect.
Smalltalk garbageCollectMost.

(Delay forMilliseconds: 500) wait.
j := self flushComponents.
].

MolUtils log: 'Deep Cleanup: ',i printString,' lost component(s) found and released.'.
i <= 0 ifFalse:[
j <= 0 ifFalse:[
MolUtils showInformation: 'Warning : Cannot release ',i printString,' component(s) after two clean pass, please try again to confirm correct cleanup.'.
] ifTrue:[
MolUtils showInformation: 'Clean success : ',i printString,' lost component(s) found and released.'.
].
] ifTrue:[
MolUtils showInformation: 'No problem : image was clean.'.
].

MolUtils log: 'End of the deep cleanUp.'.
j := self flushComponents ].

MolUtils log: 'Deep Cleanup: ' , i printString
, ' lost component(s) found and released.'.
i <= 0
ifFalse: [
j <= 0
ifFalse: [
MolUtils showInformation:
'Warning : Cannot release ' , i printString
,
' component(s) after two clean pass, please try again to confirm correct cleanup.' ]
ifTrue: [
MolUtils showInformation: 'Clean success : ' , i printString
, ' lost component(s) found and released.' ] ]
ifTrue: [ MolUtils showInformation: 'No problem : image was clean.' ].

MolUtils log: 'End of the deep cleanUp.'
]

{ #category : #singleton }
Expand All @@ -104,23 +113,25 @@ MolComponentManager class >> default [

{ #category : #'initialize-release' }
MolComponentManager class >> flushComponents [
"Flush all components : detect all component class instances of the Pharo image and disconnect each componentconnector, return number of flushed components"
"Flush all components : detect all component class instances of the Pharo image and disconnect each component connector, return number of flushed components"

| i |
i := 0.
"First : search direct component class subinstances (inheritance from MolAbstractComponentImpl class)"
MolAbstractComponentImpl allSubInstancesDo:[ :component |
component componentConnector: nil. i := i + 1.
].
"Second : search augmented class as a component instances (using the MolComponentImpl trait)"
MolComponentImpl users do: [ :impl |
impl allInstances do: [:component | component componentConnector: nil. i := i + 1].
].

MolAbstractComponentImpl allSubInstancesDo: [ :component |
component componentConnector: nil.
i := i + 1 ].
"Second : search augmented class component instances (using the MolComponentImpl trait)"
MolComponentImpl users do: [ :impl |
impl allInstances do: [ :component |
component componentConnector: nil.
i := i + 1 ] ].

SmalltalkImage cleanUp.
Smalltalk garbageCollect.
Smalltalk garbageCollectMost.
^i

^ i
]

{ #category : #'initialize-release' }
Expand Down

0 comments on commit adcf24e

Please sign in to comment.