Skip to content

Commit 7cc4f4b

Browse files
authored
Merge pull request #36 from intersystems/InteropProcesses
Interoperability Process Tracking
2 parents 59997fb + c153244 commit 7cc4f4b

File tree

4 files changed

+48
-6
lines changed

4 files changed

+48
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [3.2.0] - 2024-07-05
9+
10+
### Added
11+
- #14: Added a straightforward way to find and track coverage on all interoperability processes in the current namespace
12+
813
## [3.1.0] - 2024-01-17
914

1015
### Changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Where:
101101
* `tCoverageLevel` (optional) is 0 to track code coverage overall; 1 to track it per test suite (the default); 2 to track it per test class; 3 to track it per test method.
102102
* `tLogIndex` (optional) allows for aggregation of code coverage results across unit test runs. To use this, get it back as output from the first test run, then pass it to the next.
103103
* `tSourceNamespace` (optional) specifies the namespace in which classes were compiled, defaulting to the current namespace. This may be required to retrieve some metadata.
104-
* `tPIDList` (optional) has a $ListBuild list of process IDs to monitor. If this is empty, all processes are monitored. By default, only the current process is monitored.
104+
* `tPIDList` (optional) has a $ListBuild list of process IDs to monitor. If this is empty, all processes are monitored. If this is $ListBuild("Interop") or "Interoperability", all interoperability processes and the current process are monitored. By default, only the current process is monitored.
105105
* `tTiming` (optional) is 1 to capture execution time data for monitored classes/routines as well, or 0 (the default) to not capture this data.
106106

107107
### Viewing Results

cls/TestCoverage/Manager.cls

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ Property SourceNamespace As %String(MAXLEN = 255) [ Internal, Private ];
5050

5151
Property ProcessIDs As %List [ Internal, Private ];
5252

53+
/// 0 means don't bother with interoperability processes, 1 means track interoperability processes
54+
Property InteroperabilityProcesses As %Integer [ InitialExpression = 0, Internal, Private ];
55+
5356
Property Run As TestCoverage.Data.Run;
5457

5558
/// Known coverage targets (already snapshotted). <br />
@@ -73,7 +76,7 @@ Property Monitor As TestCoverage.Utils.LineByLineMonitor [ InitialExpression = {
7376
/// Note that overall tracking is always available; more granular tracking requires more time and disk space.</li>
7477
/// <li><var>pLogIndex</var> (optional) allows for aggregation of code coverage results across unit test runs. To use this, get it back as output from the first test run, then pass it to the next.</li>
7578
/// <li><var>pSourceNamespace</var> (optional) specifies the namespace in which classes were compiled, defaulting to the current namespace. This may be required to retrieve some metadata.</li>
76-
/// <li><var>pPIDList</var> (optional) has a $ListBuild list of process IDs to monitor. If this is empty, all processes are monitored. By default, this is just the current process.</li>
79+
/// <li><var>pPIDList</var> (optional) has a $ListBuild list of process IDs to monitor. If this is empty, all processes are monitored. If this is $listbuild("Interop") or "Interoperability", the current process and all interoperability processes are monitored. By default, this is just the current process.</li>
7780
/// <li><var>pTiming</var> (optional) may be set to 1 to also collect timing information per line.</li>
7881
/// </ul>
7982
/// Granular data is stored in <class>TestCoverage.Data.Coverage</class>; aggregated data is stored per class in <class>TestCoverage.Data.Aggregate.ByCodeUnit</class> and for the whole run in <class>TestCoverage.Data.Aggregate.ByRun</class>.
@@ -176,14 +179,39 @@ Method CoverageTargetsSet(%value) As %Status [ Internal, Private ]
176179
Quit $$$OK
177180
}
178181

182+
/// Collect the list of PIDs used by Interoperability processes in the current namespace
183+
/// In order to run unit tests collecting coverage in that specific list of processes (plus the current process)
184+
Method GetInteropProcesses(Output tProcessIDs)
185+
{
186+
&sql(select %DLIST(Process) into :tProcessIDs from %SYS.ProcessQuery_SS() where "User" = '_Ensemble' and Namespace = $Namespace)
187+
If (SQLCODE < 0) {
188+
Throw ##class(%Exception.SQL).CreateFromSQLCODE(SQLCODE,%msg)
189+
}
190+
if ('$LISTFIND(tProcessIDs, $Job)) {
191+
set tProcessIDs = tProcessIDs _ $ListBuild($Job)
192+
}
193+
}
194+
195+
/// Overriden LogAssert method because we want to be able to hook into the StartProduction() call in subclasses of %UnitTest.TestProduction
196+
/// in order to get the interoperability process list after the production has started
197+
Method LogAssert(success, action, description, extra, args...)
198+
{
199+
do ##super(.success, .action, .description, .extra, args...)
200+
if (..InteroperabilityProcesses && (description = "StartProduction()")) {
201+
do ..GetInteropProcesses(.tProcessIDs)
202+
set ..ProcessIDs = tProcessIDs
203+
$$$ThrowOnError(..EndCoverageTracking())
204+
$$$ThrowOnError(..StartCoverageTracking())
205+
}
206+
}
207+
179208
Method StartCoverageTracking() As %Status [ Private ]
180209
{
181210
Set tSC = $$$OK
182211
New $Namespace
183212
Try {
184213
If (..CoverageTargets '= "") {
185214
Set $Namespace = ..SourceNamespace
186-
187215
Set tRelevantTargets = ""
188216
Set tNewTargets = ""
189217
Set tPointer = 0
@@ -242,6 +270,10 @@ Method StartCoverageTracking() As %Status [ Private ]
242270
}
243271
}
244272
}
273+
ElseIf (..InteroperabilityProcesses)
274+
{
275+
do ..GetInteropProcesses(.tProcessIDs)
276+
}
245277
Set tMetrics = $ListBuild("RtnLine") _ $Select(..Timing:$ListBuild("Time","TotalTime"),1:"")
246278
$$$ThrowOnError(..Monitor.StartWithScope(tRelevantTargets,tMetrics,tProcessIDs))
247279
}
@@ -534,8 +566,14 @@ ClassMethod OnBeforeAllTests(manager As TestCoverage.Manager, dir As %String, By
534566
Set tProcessIDs = $Get(userparam("ProcessIDs"),$ListBuild($Job))
535567
If (tProcessIDs = "*") {
536568
Set tProcessIDs = ""
537-
} ElseIf (tProcessIDs = "") || '$ListValid(tProcessIDs) {
569+
} ElseIf ((tProcessIDs = "Interoperability") || (tProcessIDs = "interoperability")) {
570+
Set manager.InteroperabilityProcesses = 1
571+
Set tProcessIDs = $lb("Interop")
572+
}
573+
ElseIf (tProcessIDs = "") || '$ListValid(tProcessIDs) {
538574
Set tProcessIDs = $ListBuild($Job)
575+
} ElseIf (($list(tProcessIDs, 1)="Interop") || ($list(tProcessIDs, 1)="interop") ) {
576+
Set manager.InteroperabilityProcesses = 1
539577
}
540578
Set tTiming = $Get(userparam("Timing"),0)
541579
Set tSubject = $Get(userparam("Subject"))
@@ -762,4 +800,3 @@ ClassMethod GetURL(pRunID As %String, Output pHost As %String, Output pPath As %
762800
}
763801

764802
}
765-

module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Export generator="Cache" version="25">
33
<Document name="TestCoverage.ZPM"><Module>
44
<Name>TestCoverage</Name>
5-
<Version>3.1.0</Version>
5+
<Version>3.2.0</Version>
66
<Description>Run your typical ObjectScript %UnitTest tests and see which lines of your code are executed. Includes Cobertura-style reporting for use in continuous integration tools.</Description>
77
<Packaging>module</Packaging>
88
<Resource Name="TestCoverage.PKG" Directory="cls" />

0 commit comments

Comments
 (0)