[squeak-dev] The Trunk: CollectionsTests-eem.342.mcz

Levente Uzonyi leves at caesar.elte.hu
Sun Sep 27 22:12:40 UTC 2020


Hi Eliot,

The new test has revealed a difference in #nextOrNilSuchThat: between 
SharedQueue and SharedQueue2.
In SharedQueue, if there's an element matching the argument block, all 
preceding elements are removed from the queue. That is not what I would 
expect from such method, and that behavior contradicts the method's 
comment.

Fortunately, #nextOrNilSuchThat: has no real users in the Trunk.
Etoys has EventSensor >> #hasDandDEvents which uses #nextOrNilSuchThat:, 
but that method won't remove any elements, just checks if there's a 
matching event.

IMO, we should replace all uses of SharedQueue with SharedQueue2 for the 
6.0 release. A bit of surgery will be required to safely migrate all alive 
instances...


Levente

On Sat, 19 Sep 2020, commits at source.squeak.org wrote:

> Eliot Miranda uploaded a new version of CollectionsTests to project The Trunk:
> http://source.squeak.org/trunk/CollectionsTests-eem.342.mcz
>
> ==================== Summary ====================
>
> Name: CollectionsTests-eem.342
> Author: eem
> Time: 19 September 2020, 1:11:15.902536 pm
> UUID: ba823c3b-42f7-4276-8a25-8c59d26a3346
> Ancestors: CollectionsTests-ul.341
>
> Refator SHaredQueue2Test so that now we also test SharedQueue.  Add a test for peek and peekLast
>
> =============== Diff against CollectionsTests-ul.341 ===============
>
> Item was added:
> + TestCase subclass: #AbstractSharedQueueTest
> + 	instanceVariableNames: ''
> + 	classVariableNames: ''
> + 	poolDictionaries: ''
> + 	category: 'CollectionsTests-Sequenceable'!
>
> Item was added:
> + ----- Method: AbstractSharedQueueTest class>>isAbstract (in category 'testing') -----
> + isAbstract
> + 	^self class == thisContext methodClass!
>
> Item was added:
> + ----- Method: AbstractSharedQueueTest>>queueClass (in category 'private') -----
> + queueClass
> + 	^self subclassResponsibility!
>
> Item was added:
> + ----- Method: AbstractSharedQueueTest>>testBasics (in category 'tests') -----
> + testBasics
> + 	| q |
> + 	q := self queueClass new.
> + 
> + 	self assert: nil equals: q nextOrNil.
> + 
> + 	q nextPut: 5.
> + 	self assert: 5 equals: q nextOrNil.
> + 	self assert: nil equals: q nextOrNil!
>
> Item was added:
> + ----- Method: AbstractSharedQueueTest>>testContention1 (in category 'tests') -----
> + testContention1
> + 	"here is a test case that breaks the standard SharedQueue from Squeak 3.8"
> + 
> + 	| q r1 r2 |
> + 	q := self queueClass new.
> + 	q nextPut: 5.
> + 	q nextPut: 10.
> + 
> + 	self assert: 5 equals: q nextOrNil.
> + 
> + 	[ r1 := q next ] fork.
> + 	[ r2 := q next ] fork.
> + 	Processor  yield.   "let the above two threads block"
> + 
> + 	q nextPut: 10.
> + 	Processor yield.
> + 
> + 	self assert: 10 equals: r1.
> + 	self assert: 10 equals: r2.
> + 	self assert: nil equals: q nextOrNil!
>
> Item was added:
> + ----- Method: AbstractSharedQueueTest>>testNextOrNilSuchThat (in category 'tests') -----
> + testNextOrNilSuchThat
> + 	| q item |
> + 	q := self queueClass new.
> + 	q nextPut: 5.
> + 	q nextPut: 6.
> + 
> + 	item := q nextOrNilSuchThat: [ :x | x even ].
> + 	self assert: 6 equals: item.
> + 
> + 	self assert: 5 equals: q nextOrNil.
> + 	self assert: nil equals: q nextOrNil!
>
> Item was added:
> + ----- Method: AbstractSharedQueueTest>>testPeeks (in category 'tests') -----
> + testPeeks
> + 	| q |
> + 	q := self queueClass new.
> + 
> + 	self assert: nil equals: q peek.
> + 	self assert: nil equals: q peekLast.
> + 
> + 	q nextPut: #first; nextPut: #last.
> + 
> + 	self assert: #first equals: q peek.
> + 	self assert: #last equals: q peekLast.
> + 
> + 	self assert: #first equals: q next.
> + 
> + 	self assert: #last equals: q peek.
> + 	self assert: #last equals: q peekLast!
>
> Item was changed:
> + AbstractSharedQueueTest subclass: #SharedQueue2Test
> - TestCase subclass: #SharedQueue2Test
>  	instanceVariableNames: ''
>  	classVariableNames: ''
>  	poolDictionaries: ''
>  	category: 'CollectionsTests-Sequenceable'!
>
> Item was added:
> + ----- Method: SharedQueue2Test>>queueClass (in category 'private') -----
> + queueClass
> + 	^SharedQueue2!
>
> Item was removed:
> - ----- Method: SharedQueue2Test>>testBasics (in category 'tests') -----
> - testBasics
> - 	| q |
> - 	q := SharedQueue2 new.
> - 
> - 	self should: [ q nextOrNil = nil ].
> - 
> - 	q nextPut: 5.
> - 	self should: [ q nextOrNil = 5 ].
> - 	self should: [ q nextOrNil = nil ].
> - 
> - !
>
> Item was removed:
> - ----- Method: SharedQueue2Test>>testContention1 (in category 'tests') -----
> - testContention1
> - 	"here is a test case that breaks the standard SharedQueue from Squeak 3.8"
> - 
> - 	| q r1 r2 |
> - 	q := SharedQueue2 new.
> - 	q nextPut: 5.
> - 	q nextPut: 10.
> - 
> - 	self should: [ q nextOrNil = 5 ].
> - 
> - 	[ r1 := q next ] fork.
> - 	[ r2 := q next ] fork.
> - 	Processor  yield.   "let the above two threads block"
> - 
> - 	q nextPut: 10.
> - 	Processor yield.
> - 
> - 	self should: [ r1 = 10 ].
> - 	self should: [ r2 = 10 ].
> - 	self should: [ q nextOrNil = nil ].
> - !
>
> Item was removed:
> - ----- Method: SharedQueue2Test>>testNextOrNilSuchThat (in category 'tests') -----
> - testNextOrNilSuchThat
> - 	| q item |
> - 	q := SharedQueue2 new.
> - 	q nextPut: 5.
> - 	q nextPut: 6.
> - 
> - 	item := q nextOrNilSuchThat: [ :x | x even ].
> - 	self should: [ item = 6 ].
> - 
> - 	self should: [ q nextOrNil = 5 ].
> - 	self should: [ q nextOrNil = nil ].
> - !
>
> Item was added:
> + AbstractSharedQueueTest subclass: #SharedQueueTest
> + 	instanceVariableNames: ''
> + 	classVariableNames: ''
> + 	poolDictionaries: ''
> + 	category: 'CollectionsTests-Sequenceable'!
>
> Item was added:
> + ----- Method: SharedQueueTest>>queueClass (in category 'private') -----
> + queueClass
> + 	^SharedQueue!


More information about the Squeak-dev mailing list