Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For Pharo 12 Tests #176

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading