Skip to content

Commit

Permalink
fixup! ThreadMonitor : Add class for monitoring threads used for proc…
Browse files Browse the repository at this point in the history
…esses

This test was broken in so many ways :

- It used the wrong string for the compute process type.
- It didn't construct the ThreadMonitor with a process mask.
- It assumed there would only ever be one compute, but actually multiple computes can be done if multiple threads start the compute before the result is cached.

To fix the latter problems, we just launch all the processes on the main thread - we're testing the masking, not the thread handling.
  • Loading branch information
johnhaddon committed Aug 17, 2023
1 parent f076d9d commit f7341df
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions python/GafferTest/ThreadMonitorTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,30 +114,29 @@ def testMonitoring( self ) :

def testProcessMask( self ) :

for processType in [ "computeNode:hash", "computeNode:value" ] :
for processType in [ "computeNode:hash", "computeNode:compute" ] :

with self.subTest( processType = processType ) :

Gaffer.ValuePlug.clearCache()
Gaffer.ValuePlug.clearHashCache()

random = Gaffer.Random()
threadMonitor = Gaffer.ThreadMonitor()
threadMonitor = Gaffer.ThreadMonitor( processMask = { processType } )
performanceMonitor = Gaffer.PerformanceMonitor()
context = Gaffer.Context()

with threadMonitor, performanceMonitor :
GafferTest.parallelGetValue( random["outFloat"], 5, "test" )
with threadMonitor, performanceMonitor, context :
for i in range( 0, 5 ) :
context["i"] = i # Unique context to force hashing
random["outFloat"].getValue()

self.assertEqual(
performanceMonitor.plugStatistics( random["outFloat"] ).computeCount, 1
)
self.assertEqual(
performanceMonitor.plugStatistics( random["outFloat"] ).hashCount, 5
)
self.assertEqual( performanceMonitor.plugStatistics( random["outFloat"] ).computeCount, 1 )
self.assertEqual( performanceMonitor.plugStatistics( random["outFloat"] ).hashCount, 5 )

self.assertEqual(
sum( threadMonitor.plugStatistics( random["outFloat"] ).values() ),
5 if processType == "computeNode:compute" else 1
1 if processType == "computeNode:compute" else 5
)

if __name__ == "__main__":
Expand Down

0 comments on commit f7341df

Please sign in to comment.