RegressionTests__ProcessTest.st
changeset 1447 2351db93aa5b
parent 1292 2c3259f8a35d
child 1500 d406a10b2965
child 2048 e181a41f5238
equal deleted inserted replaced
1446:c3b09cef9f87 1447:2351db93aa5b
     1 "{ Encoding: utf8 }"
     1 "{ Encoding: utf8 }"
     2 
     2 
     3 "{ Package: 'exept:regression' }"
     3 "{ Package: 'stx:goodies/regression' }"
     4 
     4 
     5 "{ NameSpace: RegressionTests }"
     5 "{ NameSpace: RegressionTests }"
     6 
     6 
     7 TestCase subclass:#ProcessTest
     7 TestCase subclass:#ProcessTest
     8 	instanceVariableNames:'subProcesses'
     8 	instanceVariableNames:'subProcesses'
    14 
    14 
    15 !ProcessTest methodsFor:'test'!
    15 !ProcessTest methodsFor:'test'!
    16 
    16 
    17 tearDown
    17 tearDown
    18 
    18 
    19     subProcesses notEmptyOrNil ifTrue:[ 
    19     subProcesses notEmptyOrNil ifTrue:[
    20         subProcesses do:[:aProcess|
    20 	subProcesses do:[:aProcess|
    21             aProcess terminate.
    21 	    aProcess terminate.
    22         ].
    22 	].
    23     ].
    23     ].
    24 
    24 
    25     "Modified: / 19-09-2014 / 13:27:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    25     "Modified: / 19-09-2014 / 13:27:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    26 !
    26 !
    27 
    27 
    29     "This test makes sure a process id never exeeds MaxProcessId."
    29     "This test makes sure a process id never exeeds MaxProcessId."
    30 
    30 
    31     | blocker lastId maxId iters |
    31     | blocker lastId maxId iters |
    32 
    32 
    33 
    33 
    34     self 
    34     self
    35         skipIf: Processor maxProcessId > 500000
    35 	skipIf: Processor maxProcessId > 500000
    36         description: 'Processor maxProcessId is huge, would take really a long time'.
    36 	description: 'Processor maxProcessId is huge, would take really a long time'.
    37 
    37 
    38     blocker := Semaphore new.
    38     blocker := Semaphore new.
    39     lastId := Processor activeProcess id.
    39     lastId := Processor activeProcess id.
    40     maxId := Processor maxProcessId.
    40     maxId := Processor maxProcessId.
    41 
    41 
    42     iters := 0.
    42     iters := 0.
    43     [ lastId ~~ maxId ] whileTrue:[
    43     [ lastId ~~ maxId ] whileTrue:[
    44         [ lastId := Processor activeProcess id. blocker signal ] fork.
    44 	[ lastId := Processor activeProcess id. blocker signal ] fork.
    45         blocker wait.
    45 	blocker wait.
    46         iters := iters + 1.
    46 	iters := iters + 1.
    47         iters > maxId ifTrue:[ 
    47 	iters > maxId ifTrue:[
    48             "/ OK, we tried long enough. The system is probably already
    48 	    "/ OK, we tried long enough. The system is probably already
    49             "/ reusing Process id's so it may never reach maxId.
    49 	    "/ reusing Process id's so it may never reach maxId.
    50             ^ self.
    50 	    ^ self.
    51         ].
    51 	].
    52     ].
    52     ].
    53     "/ OK, we reached the limit. Try once again to spawn a new
    53     "/ OK, we reached the limit. Try once again to spawn a new
    54     "/ thread and assert its id is smaller then the limit.
    54     "/ thread and assert its id is smaller then the limit.
    55     [ lastId := Processor activeProcess id. blocker signal ] fork.
    55     [ lastId := Processor activeProcess id. blocker signal ] fork.
    56     blocker wait.
    56     blocker wait.
    64 testTerminateWithAllSubProcesses
    64 testTerminateWithAllSubProcesses
    65 
    65 
    66     | block masterTask allProcesses|
    66     | block masterTask allProcesses|
    67 
    67 
    68     subProcesses := OrderedCollection new.
    68     subProcesses := OrderedCollection new.
    69     block := [ 
    69     block := [
    70         1 to:10 do:[:index|
    70 	1 to:10 do:[:index|
    71             |subTask|
    71 	    |subTask|
    72             subTask := [[true] whileTrue:[]] newProcess.
    72 	    subTask := [[true] whileTrue:[]] newProcess.
    73             subTask name:'TestTask no:', index asString.
    73 	    subTask name:'TestTask no:', index asString.
    74             subTask priority:4.
    74 	    subTask priority:4.
    75             subProcesses add:subTask.
    75 	    subProcesses add:subTask.
    76             subTask resume.
    76 	    subTask resume.
    77         ].
    77 	].
    78         [true] whileTrue:[Delay waitForSeconds:10].
    78 	[true] whileTrue:[Delay waitForSeconds:10].
    79     ].
    79     ].
    80 
    80 
    81     masterTask := block newProcess.
    81     masterTask := block newProcess.
    82     masterTask beGroupLeader.
    82     masterTask beGroupLeader.
    83     masterTask priority:8.
    83     masterTask priority:8.
    85     masterTask resume.
    85     masterTask resume.
    86 
    86 
    87     Delay waitForSeconds:0.5.
    87     Delay waitForSeconds:0.5.
    88 
    88 
    89     masterTask terminateWithAllSubprocessesInGroup.
    89     masterTask terminateWithAllSubprocessesInGroup.
    90     masterTask waitUntilTerminated.          
    90     masterTask waitUntilTerminated.
    91 
    91 
    92     Delay waitForSeconds:1.
    92     Delay waitForSeconds:1.
    93     allProcesses := ProcessorScheduler knownProcesses asOrderedCollection select:[:p | p isDead not].
    93     allProcesses := ProcessorScheduler knownProcesses asOrderedCollection select:[:p | p isDead not].
    94     subProcesses do:[:aProcess|
    94     subProcesses do:[:aProcess|
    95         self should:((allProcesses includes:aProcess) not).
    95 	self should:((allProcesses includes:aProcess) not).
    96     ].
    96     ].
    97 
    97 
    98     "
    98     "
    99      self new testTerminateWithAllSubProcesses
    99      self new testTerminateWithAllSubProcesses
   100     "
   100     "