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 " |