Skip to content

Commit 04de409

Browse files
authored
Merge pull request #3583 from ErikOnBike/3582-
Fix forked processes of TestResource from being terminated between TestCase methods being executed
2 parents 2073c00 + 0ffd167 commit 04de409

3 files changed

+82
-2
lines changed

src/SUnit-Core/TestResource.class.st

+6-2
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,13 @@ TestResource class >> makeAvailable [
9797
current := nil.
9898
candidate := self new.
9999
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.
101105
candidate isAvailable ifTrue: [current := candidate]]
102-
ensure: [current == candidate ifFalse: [candidate tearDown]]
106+
ensure: [current == candidate ifFalse: [candidate tearDown]]]
103107
]
104108

105109
{ #category : #'instance creation' }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
]

0 commit comments

Comments
 (0)