Skip to content

Commit

Permalink
Merge pull request #36 from intersystems/InteropProcesses
Browse files Browse the repository at this point in the history
Interoperability Process Tracking
  • Loading branch information
isc-tleavitt authored Jul 5, 2024
2 parents 59997fb + c153244 commit 7cc4f4b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.2.0] - 2024-07-05

### Added
- #14: Added a straightforward way to find and track coverage on all interoperability processes in the current namespace

## [3.1.0] - 2024-01-17

### Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Where:
* `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.
* `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.
* `tSourceNamespace` (optional) specifies the namespace in which classes were compiled, defaulting to the current namespace. This may be required to retrieve some metadata.
* `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.
* `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.
* `tTiming` (optional) is 1 to capture execution time data for monitored classes/routines as well, or 0 (the default) to not capture this data.

### Viewing Results
Expand Down
45 changes: 41 additions & 4 deletions cls/TestCoverage/Manager.cls
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ Property SourceNamespace As %String(MAXLEN = 255) [ Internal, Private ];

Property ProcessIDs As %List [ Internal, Private ];

/// 0 means don't bother with interoperability processes, 1 means track interoperability processes
Property InteroperabilityProcesses As %Integer [ InitialExpression = 0, Internal, Private ];

Property Run As TestCoverage.Data.Run;

/// Known coverage targets (already snapshotted). <br />
Expand All @@ -73,7 +76,7 @@ Property Monitor As TestCoverage.Utils.LineByLineMonitor [ InitialExpression = {
/// Note that overall tracking is always available; more granular tracking requires more time and disk space.</li>
/// <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>
/// <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>
/// <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>
/// <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>
/// <li><var>pTiming</var> (optional) may be set to 1 to also collect timing information per line.</li>
/// </ul>
/// 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>.
Expand Down Expand Up @@ -176,14 +179,39 @@ Method CoverageTargetsSet(%value) As %Status [ Internal, Private ]
Quit $$$OK
}

/// Collect the list of PIDs used by Interoperability processes in the current namespace
/// In order to run unit tests collecting coverage in that specific list of processes (plus the current process)
Method GetInteropProcesses(Output tProcessIDs)
{
&sql(select %DLIST(Process) into :tProcessIDs from %SYS.ProcessQuery_SS() where "User" = '_Ensemble' and Namespace = $Namespace)
If (SQLCODE < 0) {
Throw ##class(%Exception.SQL).CreateFromSQLCODE(SQLCODE,%msg)
}
if ('$LISTFIND(tProcessIDs, $Job)) {
set tProcessIDs = tProcessIDs _ $ListBuild($Job)
}
}

/// Overriden LogAssert method because we want to be able to hook into the StartProduction() call in subclasses of %UnitTest.TestProduction
/// in order to get the interoperability process list after the production has started
Method LogAssert(success, action, description, extra, args...)
{
do ##super(.success, .action, .description, .extra, args...)
if (..InteroperabilityProcesses && (description = "StartProduction()")) {
do ..GetInteropProcesses(.tProcessIDs)
set ..ProcessIDs = tProcessIDs
$$$ThrowOnError(..EndCoverageTracking())
$$$ThrowOnError(..StartCoverageTracking())
}
}

Method StartCoverageTracking() As %Status [ Private ]
{
Set tSC = $$$OK
New $Namespace
Try {
If (..CoverageTargets '= "") {
Set $Namespace = ..SourceNamespace

Set tRelevantTargets = ""
Set tNewTargets = ""
Set tPointer = 0
Expand Down Expand Up @@ -242,6 +270,10 @@ Method StartCoverageTracking() As %Status [ Private ]
}
}
}
ElseIf (..InteroperabilityProcesses)
{
do ..GetInteropProcesses(.tProcessIDs)
}
Set tMetrics = $ListBuild("RtnLine") _ $Select(..Timing:$ListBuild("Time","TotalTime"),1:"")
$$$ThrowOnError(..Monitor.StartWithScope(tRelevantTargets,tMetrics,tProcessIDs))
}
Expand Down Expand Up @@ -534,8 +566,14 @@ ClassMethod OnBeforeAllTests(manager As TestCoverage.Manager, dir As %String, By
Set tProcessIDs = $Get(userparam("ProcessIDs"),$ListBuild($Job))
If (tProcessIDs = "*") {
Set tProcessIDs = ""
} ElseIf (tProcessIDs = "") || '$ListValid(tProcessIDs) {
} ElseIf ((tProcessIDs = "Interoperability") || (tProcessIDs = "interoperability")) {
Set manager.InteroperabilityProcesses = 1
Set tProcessIDs = $lb("Interop")
}
ElseIf (tProcessIDs = "") || '$ListValid(tProcessIDs) {
Set tProcessIDs = $ListBuild($Job)
} ElseIf (($list(tProcessIDs, 1)="Interop") || ($list(tProcessIDs, 1)="interop") ) {
Set manager.InteroperabilityProcesses = 1
}
Set tTiming = $Get(userparam("Timing"),0)
Set tSubject = $Get(userparam("Subject"))
Expand Down Expand Up @@ -762,4 +800,3 @@ ClassMethod GetURL(pRunID As %String, Output pHost As %String, Output pPath As %
}

}

2 changes: 1 addition & 1 deletion module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Export generator="Cache" version="25">
<Document name="TestCoverage.ZPM"><Module>
<Name>TestCoverage</Name>
<Version>3.1.0</Version>
<Version>3.2.0</Version>
<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>
<Packaging>module</Packaging>
<Resource Name="TestCoverage.PKG" Directory="cls" />
Expand Down

0 comments on commit 7cc4f4b

Please sign in to comment.