[Pkg] The Treated Inbox: KernelTests-jar.430.mcz
commits at source.squeak.org
commits at source.squeak.org
Thu Jun 9 08:05:22 UTC 2022
Marcel Taeumel uploaded a new version of KernelTests to project The Treated Inbox:
http://source.squeak.org/treated/KernelTests-jar.430.mcz
==================== Summary ====================
Name: KernelTests-jar.430
Author: jar
Time: 5 June 2022, 11:11:12.187824 pm
UUID: 209031e0-7bc5-984a-94dd-b3c3a24216c3
Ancestors: KernelTests-jar.429
Oops, fix comment in previous test KernelTests-jar.429... Sorry for the noise.
=============== Diff against KernelTests-mt.425 ===============
Item was added:
+ ----- Method: ProcessTest>>testPrioritySetBeforeSuspendedContext (in category 'tests') -----
+ testPrioritySetBeforeSuspendedContext
+ "Test whether priority is set before suspendedContext during process creation."
+
+ "Setting priority after causes an endless stream of error windows when debugging e.g.
+ [] newProcess
+ when Process Browser is open with auto-update on.
+
+ Once the suspendedContext is set, the new process is no longer considered terminated
+ and Process Browser will try to place it in its list of processes but encounters a nil error
+ when reading its priority because it has not been set yet."
+
+ | p inside |
+ inside := false.
+ p := [inside := true. [] newProcess] newProcess.
+ p runUntil: [:ctx | inside].
+ p runUntil: [:ctx | ctx selectorToSendOrSelf = #suspendedContext:].
+ "Now p is before assigning suspendedContext in Process class >> forContext:priority:
+ tempAt: 3 is the local variable 'newProcess' representing the newly created process;
+ verify whether the new process's priority has already been set."
+ self assert: (p suspendedContext tempAt: 3) priority notNil!
Item was added:
+ ----- Method: ProcessTest>>testTerminateByHighestPriorityProcess (in category 'tests') -----
+ testTerminateByHighestPriorityProcess
+ "Test temination by a highest priority process."
+
+ "Note: #terminate elevates the priority of the terminating process
+ and has to make sure it doesn't exceed the highest priority.
+ Workspace example:
+ q := [Semaphore new wait] fork.
+ p := [q terminate] forkAt: Processor highestPriority.
+ q isTerminated
+
+ We have to catch the 'Invalid priority' error via the 'error' variable
+ because #shouldnt:raise: doesn't work between two processes."
+
+ | p q error |
+ p := [Semaphore new wait] fork.
+ Processor yield.
+ self assert: p isBlocked.
+ error := false.
+ q := [[p terminate] on: Error do: [error := true]] newProcess.
+ q priority: Processor highestPriority.
+ q resume.
+ self deny: error.
+ self assert: p isTerminated.
+ self assert: q isTerminated!
Item was added:
+ ----- Method: ProcessTest>>testTerminateEnsureOnTopOfEnsure (in category 'tests') -----
+ testTerminateEnsureOnTopOfEnsure
+ "Test two ensure contexts on top of each other unwind correctly,
+ that both their unwind blocks get executed."
+
+ | beenHere beenHereToo bottom p top |
+ beenHere := beenHereToo := false.
+ bottom := Context contextEnsure: [beenHereToo := true].
+ top := Context contextEnsure: [Processor activeProcess suspend. beenHere := true].
+ top privSender: bottom.
+ p := Process forContext: top priority: Processor activeProcess priority.
+ p resume.
+ Processor yield.
+ self assert: p isSuspended.
+ p terminate.
+ self assert: beenHere & beenHereToo.
+ self assert: p isTerminated
+
+ !
Item was added:
+ ----- Method: ProcessTest>>testTerminateHandlingUnwindError (in category 'tests') -----
+ testTerminateHandlingUnwindError
+ "Test an error inside an unwind block is handled correctly."
+
+ "Workspace example:
+ [ [[Processor activeProcess terminate] ensure: [1/0]] on: ZeroDivide do: [] ] fork
+
+ ZeroDivide error should get caught by the handler without opening the Debugger.
+
+ To model this example as a test case we have to keep in mind that an error signal
+ in one thread cannot be caught in a different thread: if process 'p' signals an error
+ it won't be searching for a handler in the thread that sent 'p terminate' message.
+ So we can't do something like:
+ p := [ [ [Semaphore new wait] ensure: [1/0] ] on: ZeroDivide do: [] ] fork.
+ Processor yield.
+ self shouldnt: [p terminate] raise: Error
+ Instead, in order to catch the situation the ZeroDivide error is not caught within 'p',
+ we try to catch the UnhandledError raised in 'p' indicating the ZeroDivide has been
+ missed. "
+
+ | p error unwindBlock |
+ unwindBlock := [[1/0] on: UnhandledError do: [error := true]].
+ p := [ [ [Semaphore new wait] ensure: unwindBlock ] on: ZeroDivide do: [] ] fork.
+ Processor yield.
+ self assert: p isBlocked.
+ error := false.
+ p terminate.
+ self deny: error.
+ self assert: p isTerminated!
Item was added:
+ ----- Method: ProcessTest>>testTerminateHighestPriorityProcess (in category 'tests') -----
+ testTerminateHighestPriorityProcess
+ "Test termination of a highest priority process."
+
+ | p |
+ p := [Semaphore new wait] forkAt: Processor highestPriority.
+ Processor yield.
+ self assert: p isBlocked.
+ p terminate.
+ self assert: p isTerminated!
Item was added:
+ ----- Method: ProcessTest>>testTerminateNiledSuspendedContextProcess (in category 'tests') -----
+ testTerminateNiledSuspendedContextProcess
+ "Test a process with niled suspendedContext terminates correctly."
+
+ | p |
+ p := [] newProcess.
+ self assert: p isSuspended.
+ p suspendedContext: nil.
+ p terminate.
+ self assert: p isTerminated!
Item was added:
+ ----- Method: ProcessTest>>testTerminateSingleEnsure (in category 'tests') -----
+ testTerminateSingleEnsure
+ "Test a stack consisting of a single ensure context unwinds correctly."
+
+ | beenHere p singleton |
+ beenHere := false.
+ singleton := Context contextEnsure: [beenHere := true].
+ p := Process forContext: singleton priority: Processor activeProcess priority.
+ self assert: p isSuspended.
+ self assert: p suspendedContext sender isNil.
+ p terminate.
+ self assert: beenHere.
+ self assert: p isTerminated!
Item was added:
+ ----- Method: ProcessTest>>testTerminateWithDelayInUnwind (in category 'tests') -----
+ testTerminateWithDelayInUnwind
+ "Test the process that invoked the termination of another process waits
+ for the other process to finish unwinding."
+
+ "Insert delay into the unwind block to force rescheduling; alternatively,
+ 'Processor yield' could be used instead of 'delay wait'."
+
+ | delay p |
+ delay := Delay forMilliseconds: 10.
+ p := [[Processor activeProcess suspend] ensure: [delay wait]] fork.
+ Processor yield.
+ self assert: p isSuspended.
+ p terminate.
+ self assert: p isTerminated!
Item was added:
+ ----- Method: SemaphoreTest>>testSemaAfterCriticalWaitSuspended (in category 'tests') -----
+ testSemaAfterCriticalWaitSuspended "self run: #testSemaAfterCriticalWaitSuspended"
+ "This tests whether a semaphore that has just left the wait in Semaphore>>critical: but
+ has been suspended before termination, leaves it with signaling the associated semaphore."
+ | s p |
+ s := Semaphore new.
+ p := [s critical:[]] forkAt: Processor activePriority-1.
+ "wait until p entered the critical section"
+ [p suspendingList == s] whileFalse:[(Delay forMilliseconds: 10) wait].
+ "Now that p entered it, signal the semaphore. p now 'owns' the semaphore
+ but since we are running at higher priority than p it will not get to do
+ anything."
+ s signal.
+ self assert: p suspendingList class == LinkedList.
+ p suspend.
+ self assert: p suspendingList == nil.
+ p terminate.
+ self assert: 1 equals: s excessSignals!
More information about the Packages
mailing list