Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix (P7) forked processes of TestResource from being terminated between TestCase methods being executed #3605

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/SUnit-Core/TestResource.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ TestResource class >> makeAvailable [
current := nil.
candidate := self new.
self resources do: [:each | each availableFor: candidate].
[candidate setUp.

"Execute the TestResource's #setUp method within the DefaultExecutionEnvironment to prevent
forked processes created within #setUp from being terminated by the TestExecutionEnvironment
(in #checkForkedProcesses) it is running in."
DefaultExecutionEnvironment beActiveDuring: [[candidate setUp.
candidate isAvailable ifTrue: [current := candidate]]
ensure: [current == candidate ifFalse: [candidate tearDown]]
ensure: [current == candidate ifFalse: [candidate tearDown]]]
]

{ #category : #'instance creation' }
Expand Down
37 changes: 37 additions & 0 deletions src/SUnit-Tests/TestResourceWithForkedProcessTestCase.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"
SUnit tests for forked processes in test resources
"
Class {
#name : #TestResourceWithForkedProcessTestCase,
#superclass : #TestCase,
#category : #'SUnit-Tests-Core'
}

{ #category : #accessing }
TestResourceWithForkedProcessTestCase class >> resources [

"Answer the TestResource class having a forked process"

^ Array with: WithForkedProcessTestResource
]

{ #category : #tests }
TestResourceWithForkedProcessTestCase >> testFirst [

"Test whether the TestResource's forked process is not terminated.
A second test method will do the same and thereby validate that forked processes
of a TestResource do not get terminated (in between tests)."

self
assert: WithForkedProcessTestResource current forkedProcess isTerminated not
description: 'A forked process within a TestResource should not be terminated'
]

{ #category : #tests }
TestResourceWithForkedProcessTestCase >> testSecond [

"Test whether the TestResource's forked process is not terminated between tests"

"Use the other test method's implementation"
self testFirst
]
39 changes: 39 additions & 0 deletions src/SUnit-Tests/WithForkedProcessTestResource.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"
I am a TestResource for testing whether my forked processes do not get terminated
between individual TestCases being executed.
"
Class {
#name : #WithForkedProcessTestResource,
#superclass : #TestResource,
#instVars : [
'forkedProcess'
],
#category : #'SUnit-Tests-Resources'
}

{ #category : #accessing }
WithForkedProcessTestResource >> forkedProcess [

"Answer the receiver's forked process"

^ forkedProcess
]

{ #category : #running }
WithForkedProcessTestResource >> setUp [

"Create a forked process which should live until the #tearDown message is received.
The process is and should remain in suspended state."

super setUp.
forkedProcess := [ "empty process" ] newProcess
]

{ #category : #running }
WithForkedProcessTestResource >> tearDown [

"Terminate forked process"

super tearDown.
forkedProcess ifNotNil: [ forkedProcess terminate ]
]