Skip to content

Commit 83cb428

Browse files
authored
Merge pull request #1 from dionisiydk/dev
processTerminationLogicFixed
2 parents 5ac0838 + 9a03d19 commit 83cb428

27 files changed

Lines changed: 82 additions & 44 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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
helpers
2+
waitForkedProcesses
3+
4+
[forkedProcesses allSatisfy: [ :each | each isTerminated ]]
5+
whileFalse: [ 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]
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
tests
22
testAcquireLockWhenItsAlreadyBusy
33

4-
| lastLockAcquired |
4+
| lastLockAcquired syncSemaphore lockSemaphore |
55
lastLockAcquired := false.
6-
self fork: [ lock acquire. 10 seconds wait. ].
6+
syncSemaphore := Semaphore new.
7+
lockSemaphore := Semaphore new.
8+
self fork: [ lock acquire. syncSemaphore signal. lockSemaphore wait. ].
9+
syncSemaphore wait.
710
self fork: [ lock acquire. lastLockAcquired := true ].
8-
10 milliSeconds wait.
11+
self passForkedProcesses.
12+
lockSemaphore signal.
913

1014
self deny: lastLockAcquired
1115

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
tests
22
testReleasingLock
33

4-
| lastExecuted |
4+
| lastExecuted syncSemaphore lockSemaphore |
55
lastExecuted := false.
6-
self fork: [ lock acquire. 10 seconds wait].
6+
syncSemaphore := Semaphore new.
7+
lockSemaphore := Semaphore new.
8+
9+
self fork: [ lock acquire. syncSemaphore signal. lockSemaphore wait].
710
self fork: [ lock acquire. lastExecuted := true].
8-
10 milliSeconds wait.
11+
syncSemaphore wait.
12+
self passForkedProcesses.
913
lock release.
1014
self waitLastProcessFinished.
1115
self assert: lastExecuted

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

0 commit comments

Comments
 (0)