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

Don't filter out MSAA events for the currently focused object, even if the winEvent limit has been exceeded for that thread #11520

Merged
merged 10 commits into from
Sep 4, 2020
Merged
7 changes: 6 additions & 1 deletion source/IAccessibleHandler/orderedWinEventLimiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import winUser
from . import IAccessibleObjectIdentifierType
from logHandler import log
from . import isMSAADebugLoggingEnabled, getWinEventLogInfo


MAX_WINEVENTS_PER_THREAD = 10
Expand Down Expand Up @@ -99,9 +101,12 @@ def flushEvents(
# Increase the event count for this thread by 1.
threadCount = threadCounters.get(k[-1], 0)
threadCounters[k[-1]] = threadCount + 1
if isMSAADebugLoggingEnabled():
if threadCount == MAX_WINEVENTS_PER_THREAD:
log.debug(f"winEvent limit for thread {k[-1]} hit for this core cycle")
# Find out if this event is for an object whos events are always allowed.
eventsForObjectAlwaysAllowed = alwaysAllowedObjects and k[1:-1] in alwaysAllowedObjects
if threadCount > MAX_WINEVENTS_PER_THREAD and not eventsForObjectAlwaysAllowed:
if threadCount >= MAX_WINEVENTS_PER_THREAD and not eventsForObjectAlwaysAllowed:
# Skip this event if too many events have already been emitted for this thread
# and this event is not for an object whos events are always allowed.
continue
Expand Down
26 changes: 8 additions & 18 deletions tests/unit/test_orderedWinEventLimiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,6 @@ def test_alwaysAllowedObjects_onlyLatestEventKept(self):
# only the most recent event of each object is kept, all previous duplicates are discarded
self.assertEqual(2, len(events))

# todo: Fix assertion failures
@unittest.expectedFailure
def test_threadLimit_singleObject(self):
"""Test that only the latest events are kept when the thread limit is exceeded
"""
Expand All @@ -231,13 +229,9 @@ def test_threadLimit_singleObject(self):
limiter.addEvent(eventId, *source, threadID=0)

events = limiter.flushEvents()
errors = []
expectedEventCount = orderedWinEventLimiter.MAX_WINEVENTS_PER_THREAD
softAssert(errors, self.assertEqual, expectedEventCount, len(events)) # Fails with actual=11
self.assertListEqual([], errors)
self.assertEqual(expectedEventCount, len(events))

# todo: Fix assertion failures
@unittest.expectedFailure
def test_threadLimit_noCanary(self):
"""Test that only the latest events are kept when the thread limit is exceeded
"""
Expand All @@ -257,8 +251,6 @@ def test_threadLimit_noCanary(self):
softAssert(errors, self.assertEqual, expectedEventCount, len(events)) # Fails with 11 actual events
self.assertListEqual([], errors)

# todo: Fix assertion failures
@unittest.expectedFailure
def test_threadLimit_withCanaryAtStart(self):
"""Test that only the latest events are kept when the thread limit is exceeded
"""
Expand All @@ -284,8 +276,6 @@ def test_threadLimit_withCanaryAtStart(self):
softAssert(errors, self.assertNotIn, eventStartCanary, events)
self.assertListEqual([], errors)

# todo: Fix assertion failures
@unittest.expectedFailure
def test_threadLimit_canaryStartAndEnd(self):
"""Test that only the latest events are kept when the thread limit is exceeded
"""
Expand Down Expand Up @@ -337,7 +327,7 @@ def test_alwaysAllowedObjects(self):

events = limiter.flushEvents(alwaysAllowedObjects=[canaryObject, ])
# only the most recent event of each object is kept, all previous duplicates are discarded
self.assertEqual(12, len(events))
self.assertEqual(11, len(events))
self.assertIn(eventStartCanary, events)
self.assertEqual(eventStartCanary, events[0])
self.assertIn(eventEndCanary, events)
Expand All @@ -356,10 +346,10 @@ def test_limitEventsPerThread(self):
for e in events
]
# TODO: Note: repeated Id's (0 and 8) are EVENT_SYSTEM_FOREGROUND see test_maxFocusEvents
expectedIds = [26, 24, 19, 18, 16, 11, 10, 9, 8, 8, 4, 3, 2, 1, 0, 0]
expectedIds = [24, 19, 18, 16, 11, 10, 9, 8, 8, 4, 3, 2, 1, 0, 0]
self.assertEqual(expectedIds, windowIds)
# TODO:
# Why isn't this equal to MAX_WINEVENTS_PER_THREAD=10
# There are also 4 focus events.
# But the total is 16 not 10+4=14?
self.assertEqual(len(windowIds), 16)
# equal to MAX_WINEVENTS_PER_THREAD=10
# Plus 4 focus events,
# Plus the last menu event.
# All totalling 15.
self.assertEqual(len(windowIds), 15)
Comment on lines +351 to +355
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! 🥳