Skip to content

Commit 12830cf

Browse files
committed
Tests are improved to not rely on waiting duration.
And there is one failed test which probably shows the real problem: testTerminatingReadWhichWaitingWriteAndAnotherRead
1 parent 5ac0838 commit 12830cf

21 files changed

Lines changed: 52 additions & 26 deletions
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
helpers
2+
passForkedProcesses
3+
"While this trick looks bad it is quite difficult to control processes which are forked by tested code.
4+
This yield loop works well in practice.
5+
It allow all forked processes proceed"
6+
10 timesRepeat: [Processor yield]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
helpers
2+
waitForkedProcesses
3+
4+
[CurrentExecutionEnvironment value forkedProcesses
5+
allSatisfy: [ :each | each isTerminated ]] whileFalse: [
6+
Processor yield ]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
helpers
2+
waitUntil: conditionBlock
3+
4+
conditionBlock whileFalse: [Processor yield]

ReadWriteLock-Tests.package/ReadWriteLockTests.class/instance/testFailedReadShouldUnblockWrite.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ testFailedReadShouldUnblockWrite
66
[lock criticalRead: [ 10 milliSeconds wait. self error: 'failed read']] ifError: [ ]
77
].
88
self fork: [lock criticalWrite: [ executed := true ]].
9-
15 milliSeconds wait.
9+
self waitForkedProcesses.
1010

1111
executed should be: true
1212

ReadWriteLock-Tests.package/ReadWriteLockTests.class/instance/testFailedWriteShouldUnblockRead.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ testFailedWriteShouldUnblockRead
66
[lock criticalWrite: [ 10 milliSeconds wait. self error: 'failed write']] ifError: [ ]
77
].
88
self fork: [lock criticalRead: [ executed := true ]].
9-
15 milliSeconds wait.
9+
self waitForkedProcesses.
1010

1111
executed should be: true
1212

ReadWriteLock-Tests.package/ReadWriteLockTests.class/instance/testMultipleReadsShouldNotBlockEachOthers.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ testMultipleReadsShouldNotBlockEachOthers
1010
firstReadExecutedAfterLast := lastReadExecuted]
1111
].
1212
self fork: [lock criticalRead: [ lastReadExecuted := true ]].
13-
15 milliSeconds wait.
13+
self waitForkedProcesses.
1414

1515
lastReadExecuted should be: true.
1616
firstReadExecutedAfterLast should be: true

ReadWriteLock-Tests.package/ReadWriteLockTests.class/instance/testMultipleWritesShouldWaitEachOther.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ testMultipleWritesShouldWaitEachOther
1010
lastWriteExecutedAfterFirst := lastWriteExecuted not]
1111
].
1212
self fork: [lock criticalWrite: [ lastWriteExecuted := true ]].
13-
15 milliSeconds wait.
13+
self waitForkedProcesses.
1414

1515
lastWriteExecuted should be: true.
1616
lastWriteExecutedAfterFirst should be: true.

ReadWriteLock-Tests.package/ReadWriteLockTests.class/instance/testReadShouldWaitTwoRecursiveWritesInSameProcess.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ testReadShouldWaitTwoRecursiveWritesInSameProcess
1212
].
1313
].
1414
self fork: [ lock criticalRead: [ readExecuted := true ] ].
15-
15 milliSeconds wait.
15+
self waitForkedProcesses.
1616

1717
readExecuted should be: true.
1818
readExecutedAfterWrites should be: true

ReadWriteLock-Tests.package/ReadWriteLockTests.class/instance/testReadShouldWaitWrite.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ testReadShouldWaitWrite
1010
readExecutedAfterWrite := readExecuted not]
1111
].
1212
self fork: [lock criticalRead: [ readExecuted := true ]].
13-
15 milliSeconds wait.
13+
self waitForkedProcesses.
1414

1515
readExecuted should be: true.
1616
readExecutedAfterWrite should be: true.

ReadWriteLock-Tests.package/ReadWriteLockTests.class/instance/testRecursiveReadAndWriteInsideSameProcess.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ testRecursiveReadAndWriteInsideSameProcess
66
lock criticalRead: [
77
lock criticalWrite: [executed := true]].
88
].
9-
15 milliSeconds wait.
9+
self waitForkedProcesses.
1010

1111
executed should be: true

0 commit comments

Comments
 (0)