Tk Source Code

View Ticket
Login
Ticket UUID: f093ef67657c8413697bf261d67e3ffc44b870e9
Title: Intermittent failures of test event-86299fe7ce on Windows 10
Type: Bug Version: trunk (9.1b0)
Submitter: erikleunissen Created on: 2026-07-08 11:34:31
Subsystem: 69. Events Assigned To: nobody
Priority: 5 Medium Severity: Important
Status: Open Last Modified: 2026-07-08 12:59:22
Resolution: None Closed By: nobody
    Closed on:
Description:
Intermittent failures of test event-86299fe7ce have been reported on Windows 10
by Ashok Nadkarni, even if the code has the fix for ticket 86299fe7ce applied.
Cf. the thread:

    "Summary regarding failures of Tk test event-86299fe7ce in the context of upcoming Tk releases."

from 25/06/2026, 18:26 onwards.


The present ticket investigates this matter more closely in order to make
the test more robust.

The reported test output was:

    ==== event-86299fe7ce Generate window crossing events immediately upon
    pointer warp. See ticket #86299fe7ce FAILED
    ==== Contents of test case:

    # Let the screen pointer perform a back and forth warp in quick
    succession,
    # while immediatly providing opportunity for the event loop to service
    any
    # crossing events.
    event generate . <Motion> -warp 1 -x -50 -y 50
    update
    append result "|"
    event generate . <Motion> -warp 1 -x 50 -y 50
    update
    append result "|"
    # On MS Windows with bug present:
    # The TkWinPointerEvent mechanism doesn't detect the previous changes to
    # the position of the screen pointer because the back and forth motion
    # happens entirely within one MOUSE_TIMER_INTERVAL. The value for the
    # result variable in this case is: "|||"
    set result

    ---- Result was:
    |||
    ---- Result should have been (exact matching):
    |<Leave> .|<Enter> .|
    ==== event-86299fe7ce FAILED
User Comments: erikleunissen added on 2026-07-08 12:59:22:
Upon further inspection I was able to reproduce intermittent failures
in Windows 11 too. (I don't know why I was able to do so now, while
failing to do so previously.)

My preliminary conclusion:

There is a timing issue here: the calls to update in the test body may occur
before the pointer warp has completed and hence before the crossing events
are generated. This may be related to the explanation here:

    [https://core.tcl-lang.org/tk/file?ci=8e88882c02f64c8e&name=tests%2Ftestutils.tcl&ln=49-81]

I took this as a direction for making the test more robust: it should wait
for those crossing events actually having been serviced, instead of bluntly
calling "update". This direction implies fundamental changes to the test.

I've added a new test event-86299fe7ce.new in branch bug-f093ef6765, right
after the old test (commit [fb20a7e4a4]). The new test is intended to eventually
replace the old one. But for easy comparison I kept the old one for the time
being.

The new test measures the time elapsed after separately servicing
two consecutive crossing events. In the case without the fix/improvement from
ticket 86299fe7ce, this procedure should exceed 250 ms (the value for the
MOUSE_TIMER_INTERVAL on MS Windows). In the case where the code includes the fix,
this procedure should take no more than two rounds of the event loop,
which amounts to a one or a few milliseconds (depending on hardware, system load,
etc.).

This corresponds indeed to my timings, except for an anomaly
in the case where the fix wasn't yet applied. On my system the two
consecutive crossing events are sporadically serviced before the
MOUSE_TIMER_INTERVAL expires, in ever the same duration of around
50000 microseconds. I cannot explain this anomaly.

Luckily, the anomalous timing is still much longer than what's needed to
let two runs of the event loop complete. Therefore, it doesn't prevent us
from discerning whether Tk behaves as expected when the fix is applied.
As a result the proposed test uses a timing of less than 20000 microseconds
as the expected result.

Note: the branch has some debug statements and timings included. These
are to be removed eventually.

I'm inviting exercising of the new test, especially on Windows 10.