File tree 3 files changed +82
-2
lines changed
3 files changed +82
-2
lines changed Original file line number Diff line number Diff line change @@ -97,9 +97,13 @@ TestResource class >> makeAvailable [
97
97
current := nil .
98
98
candidate := self new .
99
99
self resources do: [:each | each availableFor: candidate].
100
- [candidate setUp.
100
+
101
+ " Execute the TestResource's #setUp method within the DefaultExecutionEnvironment to prevent
102
+ forked processes created within #setUp from being terminated by the TestExecutionEnvironment
103
+ (in #checkForkedProcesses) it is running in."
104
+ DefaultExecutionEnvironment beActiveDuring: [[candidate setUp.
101
105
candidate isAvailable ifTrue: [current := candidate]]
102
- ensure : [current == candidate ifFalse: [candidate tearDown]]
106
+ ensure : [current == candidate ifFalse: [candidate tearDown]]]
103
107
]
104
108
105
109
{ #category : #' instance creation' }
Original file line number Diff line number Diff line change
1
+ "
2
+ SUnit tests for forked processes in test resources
3
+ "
4
+ Class {
5
+ #name : #TestResourceWithForkedProcessTestCase ,
6
+ #superclass : #TestCase ,
7
+ #category : #' SUnit-Tests-Core'
8
+ }
9
+
10
+ { #category : #accessing }
11
+ TestResourceWithForkedProcessTestCase class >> resources [
12
+
13
+ " Answer the TestResource class having a forked process"
14
+
15
+ ^ Array with: WithForkedProcessTestResource
16
+ ]
17
+
18
+ { #category : #tests }
19
+ TestResourceWithForkedProcessTestCase >> testFirst [
20
+
21
+ " Test whether the TestResource's forked process is not terminated.
22
+ A second test method will do the same and thereby validate that forked processes
23
+ of a TestResource do not get terminated (in between tests)."
24
+
25
+ self
26
+ assert: WithForkedProcessTestResource current forkedProcess isTerminated not
27
+ description: ' A forked process within a TestResource should not be terminated'
28
+ ]
29
+
30
+ { #category : #tests }
31
+ TestResourceWithForkedProcessTestCase >> testSecond [
32
+
33
+ " Test whether the TestResource's forked process is not terminated between tests"
34
+
35
+ " Use the other test method's implementation"
36
+ self testFirst
37
+ ]
Original file line number Diff line number Diff line change
1
+ "
2
+ I am a TestResource for testing whether my forked processes do not get terminated
3
+ between individual TestCases being executed.
4
+ "
5
+ Class {
6
+ #name : #WithForkedProcessTestResource ,
7
+ #superclass : #TestResource ,
8
+ #instVars : [
9
+ ' forkedProcess'
10
+ ],
11
+ #category : #' SUnit-Tests-Resources'
12
+ }
13
+
14
+ { #category : #accessing }
15
+ WithForkedProcessTestResource >> forkedProcess [
16
+
17
+ " Answer the receiver's forked process"
18
+
19
+ ^ forkedProcess
20
+ ]
21
+
22
+ { #category : #running }
23
+ WithForkedProcessTestResource >> setUp [
24
+
25
+ " Create a forked process which should live until the #tearDown message is received.
26
+ The process is and should remain in suspended state."
27
+
28
+ super setUp.
29
+ forkedProcess := [ " empty process" ] newProcess
30
+ ]
31
+
32
+ { #category : #running }
33
+ WithForkedProcessTestResource >> tearDown [
34
+
35
+ " Terminate forked process"
36
+
37
+ super tearDown.
38
+ forkedProcess ifNotNil: [ forkedProcess terminate ]
39
+ ]
You can’t perform that action at this time.
0 commit comments