The record is the text of the repair. The Results table is the last run of the row.
SSWReStoreTypeTest>>testVeryLargeString (error on stock Cog only).
The dependency Pharo-SQLite3 gives the bytes of a text to
sqlite3_bind_text with the destructor SQLITE_STATIC. With that
value SQLite keeps the pointer and reads the bytes at the step. The
bytes are a ByteArray that nothing holds after the call. The test
allocates 10 MB between the bind and the step, the collector of Cog uses
the memory again, and SQLite stores other bytes. Our VM did not use the
memory again in that time. The defect is in Pharo-SQLite3, and each
text bind has it. The repair gives SQLITE_TRANSIENT, so SQLite makes
a copy.SSWReStoreBlockIfNilQueryTest>>testSelectSimpleObjectWithFunctionIfNil
has the mark of an expected failure, and the test passes (an unexpected
pass is a failure). The mark goes.SSWReStoreGeneralTest>>test01Events (expected failure). The test
needs the events of a list model of Dolphin Smalltalk. The Pharo port
uses an OrderedCollection, which sends no event. The test now sends the
event that the list model sends. The mark goes.SSWReStoreDefaultWriteTest>>testRefreshExistingObjects failed on
stock Cog in one run of two. ReStore keeps the objects that it reads in
a cache with weak values. The test asserts that an object still shows
an old value, and the address of the object is a proxy that loads
later. When the collector runs between the setUp and the test, the
object is read again and its proxy loads the new value. With a process
that forces a scavenge each millisecond the test failed in 13 of 30 runs
on stock Cog. The repair reads the value before the other session
writes. A sibling test gets the same line. After the repair: 0
failures in 30 such runs on each VM.fixes/rko281-restoreforpharo.st (7 entries).rko281/Pharo-SQLite3 and in
pharo-rdbms/Pharo-SQLite3, which has the same code.Load the package into a Pharo 14 image (build 791) with the load expression of the test run, file in the fixes file of the row if there is one, and run the test classes of the package.
"row 74"
Metacello new baseline: 'ReStore'; repository: 'github://rko281/ReStoreForPharo:main'; onConflict: [:e | e useIncoming]; load: #('Tests').Last result of the package run (stock Cog and iospharo on the same image).
| Row | Label | Load | Stock Cog | iospharo VM |
|---|---|---|---|---|
| 74 | rko281-restoreforpharo | ok | tests=2358 P=2358 F=0 E=0 S=0 T=0 X=0 | tests=2358 P=2358 F=0 E=0 S=0 T=0 X=0 |
"rko281-restoreforpharo: four groups of entries.
1. SQLite3Library text binding (dependency rko281/Pharo-SQLite3). The binding
of a text value passes the UTF-8 ByteArray of the text to sqlite3_bind_text
with the destructor argument 0 (SQLITE_STATIC). SQLITE_STATIC means that
SQLite keeps the pointer and reads the bytes later, at sqlite3_step. The
ByteArray is a temporary of SQLite3Library>>with:at:putText: and nothing keeps
the ByteArray alive (the cache 'bindings' of the statement keeps the String,
not the encoded bytes). After the bind call the ByteArray is garbage; its
memory can be moved or freed and reused by a collection before the step.
SSWReStoreTypeTest>>testVeryLargeString allocates 10 MB arrays between the
bind of the small varchar and the step, so the stock Cog collector reuses
the bytes of the small text, the row stores a wrong varchar, and the later
detect: finds no row (NotFound). The repair passes SQLITE_TRANSIENT (-1),
with which SQLite copies the bytes in the bind call. The destructor
argument becomes sqlite3_int64, because -1 must reach the 64-bit pointer
register intact (a C int leaves the upper 32 bits of the register
undefined).
2. SSWReStoreBlockIfNilQueryTest>>isExpectedFailure. The mark says that
testSelectSimpleObjectWithFunctionIfNil fails. The test passes on both VMs
(unexpected pass). The mark is stale: the repair removes the mark.
3. SSWReStoreGeneralTest>>test01Events. The test needs a list that triggers
the event #listChanged when the list changes (Dolphin ListModel). Pharo has
no ListModel, and SSWReStoreTest class>>listModelClass answers
OrderedCollection, which triggers no event. So the last assertion
(counter = #(1 2)) can never hold, and the test was marked as an expected
failure. The repair triggers #listChanged by hand after each removal, which
is what ListModel does, and keeps all four assertions. The mark is removed
in the same file.
4. SSWReStoreDefaultWriteTest>>testRefreshExistingObjects and
>>testRefreshExistingRelatedObject. ReStore keeps the objects that it
has read in a cache with weak values. Each test reads john1 from the
cache, lets a second session change the postcode of the address of john1,
and then asserts that john1 still shows the old postcode (it is not
refreshed yet). The address of john1 is a lazy proxy: it is read from the
database at the first access. When a garbage collection has removed the
objects of the set-up from the cache between the set-up and the test, john1
is read from the database again with an unloaded address. The address is
then loaded after the update of the second session, shows the new
postcode, and the assertion fails. The test passes when no collection runs
in that time (almost always on our VM, sometimes not on stock Cog). The
defect is in the test: it must load the address before the second session
changes it. The repair reads the postcode of john1 once before the
update. All assertions stay."
fix value: #SQLite3Library value: #with:at:putText:
value: [ :source | source includesSubstring: 'with: 0' ]
value:
'with: aStatement at: aColumn putText: aString
| bytes |
bytes := self pharoStringToUTF8: aString.
"SQLITE_TRANSIENT (-1): SQLite copies the bytes in this call. With 0
(SQLITE_STATIC) SQLite reads the bytes at sqlite3_step, when the garbage
collector can have moved or reused the memory of the temporary ByteArray."
^ self
apiBindText: aStatement
atColumn: aColumn
with: bytes
with: bytes size
with: -1'.
fix value: #SQLite3Library value: #apiBindText:atColumn:with:with:with:
value: [ :source | source includesSubstring: 'int anotherInteger' ]
value:
'apiBindText: aStatement atColumn: aColumn with: aString with: anInteger with: anotherInteger
"int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int, void(*)(void*))
The last argument is the destructor. It is a pointer, so it is a 64-bit integer here (SQLITE_TRANSIENT is -1)."
^ self ffiCall: #(int sqlite3_bind_text (sqlite3_stmt* aStatement, int aColumn, String aString, int anInteger, sqlite3_int64 anotherInteger))'.
fix value: #SSWReStoreBlockIfNilQueryTest value: #isExpectedFailure
value: [ :source | source includesSubstring: 'self selector =' ]
value:
'isExpectedFailure
"No test of this class is an expected failure. One test was marked, and it passes."
^ super isExpectedFailure'.
fix value: #SSWReStoreGeneralTest value: #expectedFailures
value: [ :source | source includesSubstring: '#(' ]
value:
'expectedFailures
"No test of this class is an expected failure now."
^ super expectedFailures'.
fix value: #SSWReStoreGeneralTest value: #test01Events
value: [ :source | (source includesSubstring: 'triggerEvent') not ]
value:
'test01Events
"Check persistency of events"
| t counter |
reStore refreshAllObjects.
t := (OwnerTest storedInstancesIn: reStore) last.
counter := OrderedCollection new.
reStore beginTransaction.
t single1 when: #something send: #yourself to: t.
t single1 name: ''blah''.
t list when: #listChanged send: #add: to: counter with: 1.
t ownedList when: #listChanged send: #add: to: counter with: 2.
"A Dolphin ListModel triggers #listChanged when it changes; an OrderedCollection does not, so the test triggers the event after each change"
t list removeLast.
t list triggerEvent: #listChanged.
t ownedList removeLast.
t ownedList triggerEvent: #listChanged.
reStore rollbackTransaction.
self assert: (t single1 getEvents includesKey: #something).
self assert: (t list getEvents includesKey: #listChanged).
self assert: (t ownedList getEvents includesKey: #listChanged).
self assert: (counter asSortedCollection asArray = #(1 2))'.
fix value: #SSWReStoreDefaultWriteTest value: #testRefreshExistingObjects
value: [ :source | (source includesSubstring: 'loaded before') not ]
value:
'testRefreshExistingObjects
"Test the use of the refresh message to refresh a collection of existing objects"
| zoe1 newAge zoe2 john1 john2 |
zoe1 := SimplePerson storedInstances detect: [ :each | each fullName = ''Zoe Brown''].
john1 := SimplePerson storedInstances detect: [ :each | each fullName = ''John Smith''].
"The address of john1 must be loaded before the second session changes it. The cache of ReStore holds its objects weakly: after a garbage collection john1 is read again with an unloaded address, which would be loaded after the update."
john1 address postcode.
zoe2 := (SimplePerson storedInstancesIn: reStore2) detect: [ :each | each fullName = zoe1 fullName].
newAge := zoe1 age + 1.
john2 := (SimplePerson storedInstancesIn: reStore2) detect: [ :each | each fullName = john1 fullName].
reStore2 evaluateAsTransaction:
[zoe2 age: newAge.
john2 address postcode: ''JS1 1JS''].
self assert: zoe1 age = (newAge - 1).
self assert: (john1 address postcode ~= ''JS1 1JS'').
self refreshDelay.
(Array with: zoe1 with: john1) refreshAll.
self assert: zoe1 age = newAge.
self assert: (john2 address postcode = ''JS1 1JS'')'.
fix value: #SSWReStoreDefaultWriteTest value: #testRefreshExistingRelatedObject
value: [ :source | (source includesSubstring: 'loaded before') not ]
value:
'testRefreshExistingRelatedObject
"Test the use of the refresh message to refresh an existing related object"
| john1 john2 |
john1 := SimplePerson storedInstances detect: [ :each | each fullName = ''John Smith''].
"The address of john1 must be loaded before the second session changes it (see testRefreshExistingObjects)."
john1 address postcode.
john2 := (SimplePerson storedInstancesIn: reStore2) detect: [ :each | each fullName = john1 fullName].
reStore2 evaluateAsTransaction: [john2 address postcode: ''JS1 1JS''].
self assert: (john1 address postcode ~= ''JS1 1JS'').
self refreshDelay.
john1 refresh.
self assert: (john2 address postcode = ''JS1 1JS'').'.
State of 2026-11-20. Made from the test records of the iospharo project (a second Pharo VM). The fixes are proposals for review.