The Inbox: CollectionsTests-Igor.Stasenko.169.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: CollectionsTests-Igor.Stasenko.169.mcz

commits-2
Igor Stasenko uploaded a new version of CollectionsTests to project The Inbox:
http://source.squeak.org/inbox/CollectionsTests-Igor.Stasenko.169.mcz

==================== Summary ====================

Name: CollectionsTests-Igor.Stasenko.169
Author: Igor.Stasenko
Time: 21 September 2010, 3:25:53.496 am
UUID: 64d47793-00ac-654c-926f-15d22ea84ea3
Ancestors: CollectionsTests-ar.168

- slice for a new weak finalization

=============== Diff against CollectionsTests-ar.168 ===============

Item was added:
+ WeakRegistryTest subclass: #WeakFinalizationRegistryTest
+ instanceVariableNames: ''
+ classVariableNames: ''
+ poolDictionaries: ''
+ category: 'CollectionsTests-Weak'!

Item was added:
+ ----- Method: WeakFinalizationRegistryTest>>registryClass (in category 'as yet unclassified') -----
+ registryClass
+ ^ WeakFinalizationRegistry!

Item was added:
+ ----- Method: WeakRegistryTest>>registryClass (in category 'registry') -----
+ registryClass
+ ^ WeakRegistry!

Item was changed:
  ----- Method: WeakRegistryTest>>testFinalization (in category 'tests') -----
  testFinalization
 
  | w finalized block object |
+ w := self registryClass new: 1.
- w := WeakRegistry new: 1.
  finalized := false.
  block := [ :v | finalized := v ].
  object := ObjectFinalizer "an object that responds to #finalize"
  receiver: block
  selector: #value:
  argument: true.
  w add: object.
  object := nil. "let it go"
  Smalltalk garbageCollect. "finalize it"
 
  "This is an odd issue. It seems that in some situations the finalization
  process doesn't run 'in time' for the isEmpty assertion below to succeed.
  This really *shouldn't* happen since isEmpty is full of real sends and
  there ought to be an interrupt check in there somewhere. However,
  since there are no real-time guarantees about finalization, it's fair to
  just wait a little to ensure that the finalization process has been run."
  (Delay forMilliseconds: 100) wait.
 
  self assert: w isEmpty.
  self assert: finalized!

Item was changed:
  ----- Method: WeakRegistryTest>>testFinalizationWithMultipleFinalizersPerObject (in category 'tests') -----
  testFinalizationWithMultipleFinalizersPerObject
 
  | object registry counter |
+ registry := self registryClass new.
- registry := WeakRegistry new.
  object := Object new.
  counter := 0.
  5 timesRepeat: [
  registry add: object executor: (ObjectFinalizer
  receiver: [ counter := counter + 1 ]
  selector: #value) ].
  self assert: registry size = 1.
  object := nil.
  Smalltalk garbageCollect.
  registry finalizeValues.
  self assert: registry isEmpty.
  self assert: counter = 5
  !

Item was changed:
  ----- Method: WeakRegistryTest>>testGrowingByAHighPriorityProcessDoesntLeak (in category 'tests') -----
  testGrowingByAHighPriorityProcessDoesntLeak
 
  | w finalized block object executor semaphore |
+ w := self registryClass new: 1.
- w := WeakRegistry new: 1.
  finalized := false.
  block := [ :v | finalized := v ].
  object := Object new.
  executor := ObjectFinalizer
  receiver: block
  selector: #value:
  argument: true.
  w add: object executor: executor.
  semaphore := Semaphore new.
  [
  object := nil. "let it go"
  w addAll: (1 to: 1000). "force growing"
  semaphore signal ]
  forkAt: WeakArray runningFinalizationProcess priority + 1.
  semaphore wait.
  Smalltalk garbageCollect. "finalize it"
  self assert: w size = 1000.
  self assert: finalized!

Item was changed:
  ----- Method: WeakRegistryTest>>testGrowingDoesntLeak (in category 'tests') -----
  testGrowingDoesntLeak
 
  | w finalized block object executor |
+ w := self registryClass new: 1.
- w := WeakRegistry new: 1.
  finalized := false.
  block := [ :v | finalized := v ].
  object := Object new.
  executor := ObjectFinalizer
  receiver: block
  selector: #value:
  argument: true.
  w add: object executor: executor.
  object := nil. "let it go"
  w addAll: (1 to: 1000). "force growing"
  Smalltalk garbageCollect. "finalize it"
  self assert: w size = 1000.
  self assert: finalized!

Item was changed:
  ----- Method: WeakRegistryTest>>testRemovingByAHighPriorityProcessDoesntLeak (in category 'tests') -----
  testRemovingByAHighPriorityProcessDoesntLeak
 
  | w finalized block hash object executor semaphore |
+ w := self registryClass new: 1.
- w := WeakRegistry new: 1.
  finalized := false.
  block := [ :v | finalized := v ].
  object := Object new.
  executor := ObjectFinalizer
  receiver: block
  selector: #value:
  argument: true.
  hash := object hash.
  w add: hash.
  w add: object executor: executor.
  semaphore := Semaphore new.
  [
  object := nil. "let it go"
  w remove: hash.
  semaphore signal ]
  forkAt: WeakArray runningFinalizationProcess priority + 1.
  semaphore wait.
  Smalltalk garbageCollect. "finalize it"
  self assert: w isEmpty.
  self assert: finalized!

Item was changed:
  ----- Method: WeakRegistryTest>>testRemovingDoesntLeak (in category 'tests') -----
  testRemovingDoesntLeak
 
  | w finalized block hash object executor |
+ w := self registryClass new: 1.
- w := WeakRegistry new: 1.
  finalized := false.
  block := [ :v | finalized := v ].
  object := Object new.
  executor := ObjectFinalizer
  receiver: block
  selector: #value:
  argument: true.
  hash := object hash.
  w add: hash.
  w add: object executor: executor.
  object := nil. "let it go"
  w remove: hash.
  Smalltalk garbageCollect. "finalize it"
  self assert: w isEmpty.
  self assert: finalized!