Skip to content

Commit 5e85d48

Browse files
authored
Merge pull request #51 from intersystems/PythonOnly
Python Only Tracking
2 parents a8fa2af + f9f1e8b commit 5e85d48

File tree

4 files changed

+55
-18
lines changed

4 files changed

+55
-18
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ 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+
## [4.0.2] - 2024-08-16
9+
10+
### Fixed
11+
- #51: Don't start (and stop) the ObjectScript and Python monitors if there are no ObjectScript/Python routines being tracked respectively, fixes error from trying to start/stop the %Monitor.System.LineByLine with no routines
12+
13+
814
## [4.0.1] - 2024-08-16
915

1016
### Fixed

cls/TestCoverage/Manager.cls

+15-5
Original file line numberDiff line numberDiff line change
@@ -528,10 +528,10 @@ Method EndCoverageTracking(pTestSuite As %String = "", pTestClass As %String = "
528528
Set tSC = $$$OK
529529
Try {
530530
If ((..CoverageTargets '= "") || (..PyCoverageTargets '= "")) {
531-
// Pause the monitor.
532-
Set tSC = ..Monitor.Pause()
533-
Do ##class(TestCoverage.Utils.LineByLineMonitor).PyStop()
534-
If $$$ISERR(tSC) {
531+
if (..Monitor.Started) {
532+
// Pause the monitor.
533+
Set tSC = ..Monitor.Pause()
534+
If $$$ISERR(tSC) {
535535
If $System.Status.GetErrorCodes(tSC) = $$$MonitorNotRunning {
536536
// Not really an error, and nothing to do in this case.
537537
Set tSC = $$$OK
@@ -540,6 +540,11 @@ Method EndCoverageTracking(pTestSuite As %String = "", pTestClass As %String = "
540540
$$$ThrowStatus(tSC)
541541
}
542542
}
543+
}
544+
545+
if (..Monitor.PyStarted) {
546+
Do ##class(TestCoverage.Utils.LineByLineMonitor).PyStop()
547+
}
543548

544549
Set tTarget = $ListBuild($$$TestPathAllTests) // detail = 0
545550
If (pTestSuite '= "") {
@@ -719,7 +724,12 @@ ClassMethod OnAfterAllTests(manager As TestCoverage.Manager, dir As %String, ByR
719724
Do manager.ListenerManager.BroadCastToAll(tObj)
720725
}
721726
}
722-
Do manager.Monitor.Stop()
727+
if (manager.Monitor.Started) {
728+
Do manager.Monitor.Stop()
729+
}
730+
if (manager.Monitor.PyStarted) {
731+
Do manager.Monitor.PyStop()
732+
}
723733
} Catch e {
724734
Set tSC = e.AsStatus()
725735
}

cls/TestCoverage/Utils/LineByLineMonitor.cls

+33-12
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,20 @@ Class TestCoverage.Utils.LineByLineMonitor Extends %Monitor.System.LineByLine
88
/// True if the line-by-line monitor has been started.
99
Property Started As %Boolean [ Calculated, Private, ReadOnly ];
1010

11+
/// True if the Python trace has been set
12+
Property PyStarted As %Boolean [ Calculated, Private, ReadOnly ];
13+
1114
Method StartedGet() As %Boolean [ CodeMode = expression ]
1215
{
1316
$zu(84,8)
1417
}
1518

19+
Method PyStartedGet() As %Boolean [ Language = python ]
20+
{
21+
import sys
22+
return sys.gettrace() is not None
23+
}
24+
1625
/// True if the line-by-line monitor is paused
1726
Property Paused As %Boolean [ Calculated, Private, ReadOnly ];
1827

@@ -30,6 +39,8 @@ Property LastMetricList As %List [ Private ];
3039

3140
Property LastProcessList As %List [ Private ];
3241

42+
Property LastPythonList As %List [ Private ];
43+
3344
/// This callback method is invoked by the <METHOD>%Close</METHOD> method to
3445
/// provide notification that the current object is being closed.
3546
///
@@ -98,33 +109,43 @@ Method StartWithScope(pRoutineList As %List, pPyClasses As %List, pMetricList As
98109
Set tSC = $$$OK
99110
Try {
100111
Set ..PythonClassList = pPyClasses
101-
Set tDifferentScope = (..LastRoutineList '= pRoutineList) || (..LastMetricList '= pMetricList) || (..LastProcessList '= pProcessList)
102-
If tDifferentScope && ..Started {
112+
Set tDifferentScope = (..LastRoutineList '= pRoutineList) || (..LastMetricList '= pMetricList) || (..LastProcessList '= pProcessList) || (..LastPythonList '= pPyClasses)
113+
If tDifferentScope && (..Started || ..PyStarted) {
103114
// If we need to track different routines/metrics/processes, need to stop the monitor before restarting with the new context.
104-
Do ..Stop()
105-
Do ..PyStop()
115+
If (..Started) {
116+
Do ..Stop()
117+
}
118+
Do ..PyStop() // setting the trace to None can and should always be done
106119
Set ..LastRoutineList = pRoutineList
107120
Set ..LastMetricList = pMetricList
108121
Set ..LastProcessList = pProcessList
122+
Set ..LastPythonList = pPyClasses
109123
}
110124

111-
If '..Started {
112-
Do ..PyClearCounters()
125+
// take care of starting the ObjectScript Monitor
126+
If ('..Started && $ListLength(pRoutineList) '= 0) {
113127
Set tSC = ..Start(pRoutineList, pMetricList, pProcessList)
114-
Do ..PyStartWithScope(pPyClasses)
115128
If $System.Status.Equals(tSC,$$$ERRORCODE($$$MonitorMemoryAlloc)) {
116129
// Construct a more helpful error message.
117130
Set tSC = $$$EMBEDSC(..CheckAvailableMemory($ListLength(pProcessList),$ListLength(pRoutineList),1),tSC)
118131
}
119132
$$$ThrowOnError(tSC)
120133
} Else {
121134
// If the monitor was already running, clear the counters.
122-
Set tSC = ..ClearCounters()
123-
$$$ThrowOnError(tSC)
124-
If ..Paused {
125-
$$$ThrowOnError(..Resume())
126-
Do ..PyStartWithScope(pPyClasses)
135+
if (..Started) {
136+
Set tSC = ..ClearCounters()
137+
$$$ThrowOnError(tSC)
127138
}
139+
If (..Paused && $ListLength(pRoutineList) '= 0){
140+
$$$ThrowOnError(..Resume())
141+
}
142+
}
143+
144+
If ('..PyStarted && $ListLength(pPyClasses) '= 0) {
145+
// whether we're resuming or restarting, we either way want to clear counters
146+
// since StoreIntCoverage should have already
147+
Do ..PyClearCounters()
148+
Do ..PyStartWithScope(pPyClasses)
128149
}
129150
} Catch e {
130151
Set tSC = e.AsStatus()

module.xml

+1-1
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>4.0.1</Version>
5+
<Version>4.0.2</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)