The Inbox: Tests-jar.465.mcz

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

The Inbox: Tests-jar.465.mcz

commits-2
A new version of Tests was added to project The Inbox:
http://source.squeak.org/inbox/Tests-jar.465.mcz

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

Name: Tests-jar.465
Author: jar
Time: 24 May 2021, 3:08:49.157073 pm
UUID: 18735b9b-6bdc-b349-b14f-bedaeb898934
Ancestors: Tests-jar.463

Add a set of tests comlpementing the latest #terminate in the Inbox. Tests the unwind semantics during termination.

=============== Diff against Tests-jar.463 ===============

Item was added:
+ TestCase subclass: #ProcessTerminateUnwindTests
+ instanceVariableNames: ''
+ classVariableNames: ''
+ poolDictionaries: ''
+ category: 'Tests-Exceptions'!

Item was added:
+ ----- Method: ProcessTerminateUnwindTests>>testTerminateEnsureAsTopContext (in category 'tests') -----
+ testTerminateEnsureAsTopContext
+ "Test #ensure unwind block is executed even when #ensure context is on stack's top."
+
+ | p1 p2 p3 x1 x2 x3 |
+ x1 := x2 := x3 := false.
+
+ "p1 is at the beginning of the ensure block; the unwind block hasn't run yet"
+ p1 := Process
+ forBlock: [[] ensure: [x1 := x1 not]]
+ runUntil: [:ctx | ctx isUnwindContext and: [(ctx tempAt: 2) isNil]].
+
+ "p2 has already set complete to true (tempAt: 2) but the unwind block hasn't run yet"
+ p2 := Process
+ forBlock: [[] ensure: [x2 := x2 not]]
+ runUntil: [:ctx | ctx isUnwindContext and: [(ctx tempAt: 2) notNil]].
+
+ "p3 has already set complete to true AND the unwind block has run already run;
+ we have to verify the unwind block is not executed again during termination"
+ p3 := Process
+ forBlock: [[] ensure: [x3 := x3 not]]
+ runUntil: [:ctx | ctx isUnwindContext and: [ctx willReturn]].
+
+ "make sure all processes are running and only the p3's unwind block has finished"
+ self deny: p1 isTerminated | p2 isTerminated | p3 isTerminated.
+ self deny: x1 | x2.
+ self assert: x3. "p3 has already run its unwind block; we test it won't run it again"
+ "terminate all processes and verify all unwind blocks have finished correctly"
+ p1 terminate. p2 terminate. p3 terminate.
+ self assert: p1 isTerminated & p2 isTerminated & p3 isTerminated.
+ self assert: x1 & x2 & x3!

Item was added:
+ ----- Method: ProcessTerminateUnwindTests>>testTerminationDuringNestedUnwind1 (in category 'tests') -----
+ testTerminationDuringNestedUnwind1
+ "Terminate suspended process.
+ Test all nested unwind blocks are correctly unwound;
+ all unwind blocks halfway through their execution should be completed."
+
+ | p x1 x2 x3 x4 |
+ x1 := x2 := x3 := x4 := false.
+ p :=
+ [
+ [
+ [ ] ensure: [
+ [Processor activeProcess suspend] ensure: [
+ x1 := true].
+ x2 := true]
+ ] ensure: [
+ x3 := true].
+ x4 := true.
+ ] newProcess.
+ p resume.
+ Processor yield.
+ "make sure p is suspended and none of the unwind blocks has finished yet"
+ self assert: p isSuspended.
+ self deny: x1 | x2 | x3 | x4.
+ "now terminate the process and make sure all unwind blocks have finished"
+ p terminate.
+ self assert: p isTerminated.
+ self assert: x1 & x2 & x3.
+ self deny: x4.!

Item was added:
+ ----- Method: ProcessTerminateUnwindTests>>testTerminationDuringNestedUnwind2 (in category 'tests') -----
+ testTerminationDuringNestedUnwind2
+ "Terminate suspended process.
+ Test all nested unwind blocks are correctly unwound;
+ all unwind blocks halfway through their execution should be completed."
+
+ | p x1 x2 x3 x4 |
+ x1 := x2 := x3 := x4 := false.
+ p :=
+ [
+ [
+ [ ] ensure: [
+ [ ] ensure: [
+ Processor activeProcess suspend.
+ x1 := true].
+ x2 := true]
+ ] ensure: [
+ x3 := true].
+ x4 := true.
+ ] newProcess.
+ p resume.
+ Processor yield.
+ "make sure p is suspended and none of the unwind blocks has finished yet"
+ self assert: p isSuspended.
+ self deny: x1 | x2 | x3 | x4.
+ "now terminate the process and make sure all unwind blocks have finished"
+ p terminate.
+ self assert: p isTerminated.
+ self assert: x1 & x2 & x3.
+ self deny: x4.!

Item was added:
+ ----- Method: ProcessTerminateUnwindTests>>testTerminationDuringNestedUnwind3 (in category 'tests') -----
+ testTerminationDuringNestedUnwind3
+ "Terminate runnable process.
+ Test all nested unwind blocks are correctly unwound;
+ all unwind blocks halfway through their execution should be completed."
+
+ | p x1 x2 x3 x4 |
+ x1 := x2 := x3 := x4 := false.
+ p :=
+ [
+ [
+ [ ] ensure: [
+ [Processor yield] ensure: [
+ x1 := true].
+ x2 := true]
+ ] ensure: [
+ x3 := true].
+ x4 := true.
+ ] newProcess.
+ p resume.
+ Processor yield.
+ "make sure p is runnable and none of the unwind blocks has finished yet"
+ self assert: p isRunnable.
+ self deny: x1 | x2 | x3 | x4.
+ "now terminate the process and make sure all unwind blocks have finished"
+ p terminate.
+ self assert: p isTerminated.
+ self assert: x1 & x2 & x3.
+ self deny: x4.!

Item was added:
+ ----- Method: ProcessTerminateUnwindTests>>testTerminationDuringNestedUnwind4 (in category 'tests') -----
+ testTerminationDuringNestedUnwind4
+ "Terminate runnable process.
+ Test all nested unwind blocks are correctly unwound;
+ all unwind blocks halfway through their execution should be completed."
+
+ | p x1 x2 x3 x4 |
+ x1 := x2 := x3 := x4 := false.
+ p :=
+ [
+ [
+ [ ] ensure: [
+ [ ] ensure: [
+ Processor yield.
+ x1 := true].
+ x2 := true]
+ ] ensure: [
+ x3 := true].
+ x4 := true.
+ ] newProcess.
+ p resume.
+ Processor yield.
+ "make sure p is suspended and none of the unwind blocks has finished yet"
+ self assert: p isRunnable.
+ self deny: x1 | x2 | x3 | x4.
+ "now terminate the process and make sure all unwind blocks have finished"
+ p terminate.
+ self assert: p isTerminated.
+ self assert: x1 & x2 & x3.
+ self deny: x4.!

Item was added:
+ ----- Method: ProcessTerminateUnwindTests>>testTerminationDuringNestedUnwind5 (in category 'tests') -----
+ testTerminationDuringNestedUnwind5
+ "Terminate active process.
+ Test all nested unwind blocks are correctly unwound;
+ all unwind blocks halfway through their execution should be completed."
+
+ | p x1 x2 x3 x4 |
+ x1 := x2 := x3 := x4 := false.
+ p :=
+ [
+ [
+ [ ] ensure: [
+ [Processor activeProcess terminate] ensure: [
+ x1 := true].
+ x2 := true]
+ ] ensure: [
+ x3 := true].
+ x4 := true.
+ ] newProcess.
+ p resume.
+ Processor yield.
+ "make sure p suspended itself and none of the unwind blocks has finished yet"
+ self assert: p isSuspended.
+ self deny: x1 | x2 | x3 | x4.
+ "now let the termination continue and make sure all unwind blocks have finished"
+ Processor yield.
+ self assert: p isTerminated.
+ self assert: x1 & x2 & x3.
+ self deny: x4.!

Item was added:
+ ----- Method: ProcessTerminateUnwindTests>>testTerminationDuringNestedUnwind6 (in category 'tests') -----
+ testTerminationDuringNestedUnwind6
+ "Terminate active process.
+ Test all nested unwind blocks are correctly unwound;
+ all unwind blocks halfway through their execution should be completed."
+
+ | p x1 x2 x3 x4 |
+ x1 := x2 := x3 := x4 := false.
+ p :=
+ [
+ [
+ [ ] ensure: [
+ [ ] ensure: [
+ Processor activeProcess terminate.
+ x1 := true].
+ x2 := true]
+ ] ensure: [
+ x3 := true].
+ x4 := true.
+ ] newProcess.
+ p resume.
+ Processor yield.
+ "make sure p suspended itself and none of the unwind blocks has finished yet"
+ self assert: p isSuspended.
+ self deny: x1 | x2 | x3 | x4.
+ "now let the termination continue and make sure all unwind blocks have finished"
+ Processor yield.
+ self assert: p isTerminated.
+ self assert: x1 & x2 & x3.
+ self deny: x4.!

Item was added:
+ ----- Method: ProcessTerminateUnwindTests>>testTerminationDuringNestedUnwind7 (in category 'tests') -----
+ testTerminationDuringNestedUnwind7
+ "Terminate blocked process.
+ Test all nested unwind blocks are correctly unwound;
+ all unwind blocks halfway through their execution should be completed."
+
+ | p x1 x2 x3 x4 semaphore |
+ x1 := x2 := x3 := x4 := false.
+ semaphore := Semaphore new.
+ p :=
+ [
+ [
+ [ ] ensure: [
+ [semaphore wait] ensure: [
+ x1 := true].
+ x2 := true]
+ ] ensure: [
+ x3 := true].
+ x4 := true.
+ ] newProcess.
+ p resume.
+ Processor yield.
+ "make sure p is runnable and none of the unwind blocks has finished yet"
+ self assert: p isBlocked.
+ self deny: x1 | x2 | x3 | x4.
+ "now terminate the process and make sure all unwind blocks have finished"
+ p terminate.
+ self assert: p isTerminated.
+ self assert: x1 & x2 & x3.
+ self deny: x4.!

Item was added:
+ ----- Method: ProcessTerminateUnwindTests>>testTerminationDuringNestedUnwind8 (in category 'tests') -----
+ testTerminationDuringNestedUnwind8
+ "Terminate blocked process.
+ Test all nested unwind blocks are correctly unwound;
+ all unwind blocks halfway through their execution should be completed."
+
+ | p x1 x2 x3 x4 semaphore |
+ x1 := x2 := x3 := x4 := false.
+ semaphore := Semaphore new.
+ p :=
+ [
+ [
+ [ ] ensure: [
+ [ ] ensure: [
+ semaphore wait.
+ x1 := true].
+ x2 := true]
+ ] ensure: [
+ x3 := true].
+ x4 := true.
+ ] newProcess.
+ p resume.
+ Processor yield.
+ "make sure p is runnable and none of the unwind blocks has finished yet"
+ self assert: p isBlocked.
+ self deny: x1 | x2 | x3 | x4.
+ "now terminate the process and make sure all unwind blocks have finished"
+ p terminate.
+ self assert: p isTerminated.
+ self assert: x1 & x2 & x3.
+ self deny: x4.!

Item was added:
+ ----- Method: ProcessTerminateUnwindTests>>testTerminationDuringNestedUnwindWithReturn1 (in category 'tests') -----
+ testTerminationDuringNestedUnwindWithReturn1
+ "Terminate suspended process.
+ Test all nested unwind blocks are correctly unwound;
+ all unwind blocks halfway through their execution should be completed."
+
+ | p x1 x2 x3 x4 |
+ x1 := x2 := x3 := x4 := false.
+ p :=
+ [
+ [:return |
+ [
+ [ ] ensure: [
+ [Processor activeProcess suspend] ensure: [
+ x1 := true. return value].
+ x2 := true]
+ ] ensure: [
+ x3 := true].
+ x4 := true.
+ ] valueWithExit
+ ] newProcess.
+ p resume.
+ Processor yield.
+ "make sure p is suspended and none of the unwind blocks has finished yet"
+ self assert: p isSuspended.
+ self deny: x1 | x2 | x3 | x4.
+ "now terminate the process and make sure all unwind blocks have finished"
+ p terminate.
+ self assert: p isTerminated.
+ self assert: x1 & x3.
+ self deny: x2 & x4.!

Item was added:
+ ----- Method: ProcessTerminateUnwindTests>>testTerminationDuringNestedUnwindWithReturn2 (in category 'tests') -----
+ testTerminationDuringNestedUnwindWithReturn2
+ "Terminate suspended process.
+ Test all nested unwind blocks are correctly unwound;
+ all unwind blocks halfway through their execution should be completed."
+
+ | p x1 x2 x3 x4 |
+ x1 := x2 := x3 := x4 := false.
+ p :=
+ [
+ [:return |
+ [
+ [ ] ensure: [
+ [] ensure: [
+ Processor activeProcess suspend.
+ x1 := true. return value].
+ x2 := true]
+ ] ensure: [
+ x3 := true].
+ x4 := true.
+ ] valueWithExit
+ ] newProcess.
+ p resume.
+ Processor yield.
+ "make sure p is suspended and none of the unwind blocks has finished yet"
+ self assert: p isSuspended.
+ self deny: x1 | x2 | x3 | x4.
+ "now terminate the process and make sure all unwind blocks have finished"
+ p terminate.
+ self assert: p isTerminated.
+ self assert: x1 & x3.
+ self deny: x2 & x4.!

Item was added:
+ ----- Method: ProcessTerminateUnwindTests>>testTerminationDuringNestedUnwindWithReturn3 (in category 'tests') -----
+ testTerminationDuringNestedUnwindWithReturn3
+ "Terminate suspended process.
+ Test all nested unwind blocks are correctly unwound;
+ all unwind blocks halfway through their execution should be completed."
+
+ | p x1 x2 x3 x4 |
+ x1 := x2 := x3 := x4 := false.
+ p :=
+ [
+ [:return |
+ [
+ [ ] ensure: [
+ [Processor activeProcess suspend] ensure: [
+ x1 := true].
+ x2 := true. return value]
+ ] ensure: [
+ x3 := true].
+ x4 := true.
+ ] valueWithExit
+ ] newProcess.
+ p resume.
+ Processor yield.
+ "make sure p is suspended and none of the unwind blocks has finished yet"
+ self assert: p isSuspended.
+ self deny: x1 | x2 | x3 | x4.
+ "now terminate the process and make sure all unwind blocks have finished"
+ p terminate.
+ self assert: p isTerminated.
+ self assert: x1 & x2 & x3.
+ self deny: x4.!

Item was added:
+ ----- Method: ProcessTerminateUnwindTests>>testTerminationDuringNestedUnwindWithReturn4 (in category 'tests') -----
+ testTerminationDuringNestedUnwindWithReturn4
+ "Terminate suspended process.
+ Test all nested unwind blocks are correctly unwound;
+ all unwind blocks halfway through their execution should be completed."
+
+ | p x1 x2 x3 x4 |
+ x1 := x2 := x3 := x4 := false.
+ p :=
+ [
+ [:return |
+ [
+ [ ] ensure: [
+ [] ensure: [
+ Processor activeProcess suspend.
+ x1 := true].
+ x2 := true. return value]
+ ] ensure: [
+ x3 := true].
+ x4 := true.
+ ] valueWithExit
+ ] newProcess.
+ p resume.
+ Processor yield.
+ "make sure p is suspended and none of the unwind blocks has finished yet"
+ self assert: p isSuspended.
+ self deny: x1 | x2 | x3 | x4.
+ "now terminate the process and make sure all unwind blocks have finished"
+ p terminate.
+ self assert: p isTerminated.
+ self assert: x1 & x2 & x3.
+ self deny: x4.!

Item was added:
+ ----- Method: ProcessTerminateUnwindTests>>testTerminationDuringNestedUnwindWithReturn5 (in category 'tests') -----
+ testTerminationDuringNestedUnwindWithReturn5
+ "Terminate suspended process.
+ Test all nested unwind blocks are correctly unwound;
+ all unwind blocks halfway through their execution should be completed."
+
+ | p x1 x2 x3 x4 |
+ x1 := x2 := x3 := x4 := false.
+ p :=
+ [
+ [:return |
+ [
+ [ ] ensure: [
+ [Processor activeProcess suspend] ensure: [
+ x1 := true].
+ x2 := true]
+ ] ensure: [
+ x3 := true. return value].
+ x4 := true.
+ ] valueWithExit
+ ] newProcess.
+ p resume.
+ Processor yield.
+ "make sure p is suspended and none of the unwind blocks has finished yet"
+ self assert: p isSuspended.
+ self deny: x1 | x2 | x3 | x4.
+ "now terminate the process and make sure all unwind blocks have finished"
+ p terminate.
+ self assert: p isTerminated.
+ self assert: x1 & x2 & x3.
+ self deny: x4.!

Item was added:
+ ----- Method: ProcessTerminateUnwindTests>>testTerminationDuringNestedUnwindWithReturn6 (in category 'tests') -----
+ testTerminationDuringNestedUnwindWithReturn6
+ "Terminate suspended process.
+ Test all nested unwind blocks are correctly unwound;
+ all unwind blocks halfway through their execution should be completed."
+
+ | p x1 x2 x3 x4 |
+ x1 := x2 := x3 := x4 := false.
+ p :=
+ [
+ [:return |
+ [
+ [ ] ensure: [
+ [] ensure: [
+ Processor activeProcess suspend.
+ x1 := true].
+ x2 := true]
+ ] ensure: [
+ x3 := true. return value].
+ x4 := true.
+ ] valueWithExit
+ ] newProcess.
+ p resume.
+ Processor yield.
+ "make sure p is suspended and none of the unwind blocks has finished yet"
+ self assert: p isSuspended.
+ self deny: x1 | x2 | x3 | x4.
+ "now terminate the process and make sure all unwind blocks have finished"
+ p terminate.
+ self assert: p isTerminated.
+ self assert: x1 & x2 & x3.
+ self deny: x4.!

Item was added:
+ ----- Method: ProcessTerminateUnwindTests>>testTerminationDuringNestedUnwindWithReturn7 (in category 'tests') -----
+ testTerminationDuringNestedUnwindWithReturn7
+ "Terminate suspended process.
+ Test all nested unwind blocks are correctly unwound;
+ all unwind blocks halfway through their execution should be completed."
+
+ | p x1 x2 x3 x4 |
+ x1 := x2 := x3 := x4 := false.
+ p :=
+ [
+ [:return |
+ [
+ [ ] ensure: [
+ [Processor activeProcess suspend] ensure: [
+ x1 := true].
+ x2 := true]
+ ] ensure: [
+ x3 := true].
+ x4 := true. return value.
+ ] valueWithExit
+ ] newProcess.
+ p resume.
+ Processor yield.
+ "make sure p is suspended and none of the unwind blocks has finished yet"
+ self assert: p isSuspended.
+ self deny: x1 | x2 | x3 | x4.
+ "now terminate the process and make sure all unwind blocks have finished"
+ p terminate.
+ self assert: p isTerminated.
+ self assert: x1 & x2 & x3.
+ self deny: x4.!

Item was added:
+ ----- Method: ProcessTerminateUnwindTests>>testTerminationDuringNestedUnwindWithReturn8 (in category 'tests') -----
+ testTerminationDuringNestedUnwindWithReturn8
+ "Terminate suspended process.
+ Test all nested unwind blocks are correctly unwound;
+ all unwind blocks halfway through their execution should be completed."
+
+ | p x1 x2 x3 x4 |
+ x1 := x2 := x3 := x4 := false.
+ p :=
+ [
+ [:return |
+ [
+ [ ] ensure: [
+ [] ensure: [
+ Processor activeProcess suspend.
+ x1 := true].
+ x2 := true]
+ ] ensure: [
+ x3 := true].
+ x4 := true. return value.
+ ] valueWithExit
+ ] newProcess.
+ p resume.
+ Processor yield.
+ "make sure p is suspended and none of the unwind blocks has finished yet"
+ self assert: p isSuspended.
+ self deny: x1 | x2 | x3 | x4.
+ "now terminate the process and make sure all unwind blocks have finished"
+ p terminate.
+ self assert: p isTerminated.
+ self assert: x1 & x2 & x3.
+ self deny: x4.!