import time

import pytest
from PySide6.QtCore import QTimer
from PySide6.QtWidgets import QApplication

# edited by glg
pytestmark = [pytest.mark.perf_smoke, pytest.mark.non_functional]


def test_qt_event_loop_burst_perf_smoke():
    app = QApplication.instance()
    if app is None:
        app = QApplication([])

    total_events = 2500
    state = {"count": 0}

    def _increment():
        state["count"] += 1

    started_at = time.perf_counter()
    for _ in range(total_events):
        QTimer.singleShot(0, _increment)

    deadline = started_at + 4.0
    while state["count"] < total_events and time.perf_counter() < deadline:
        app.processEvents()

    elapsed_ms = (time.perf_counter() - started_at) * 1000.0
    assert state["count"] == total_events
    assert elapsed_ms < 4000.0
