aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_mainwindow.cpp
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-08-06 19:32:22 +0200
committerDanilo M. <danix@danix.xyz>2026-08-06 19:32:22 +0200
commiteef7f6cc1b2f845d2ca1eba53336f64597c49e62 (patch)
tree61a2168834a623c1afa5e898996f8ae036e44d36 /tests/test_mainwindow.cpp
parentddb4ac26b7fb553c9349401dda4510636c67cc9b (diff)
downloadqtmaildir-eef7f6cc1b2f845d2ca1eba53336f64597c49e62.tar.gz
qtmaildir-eef7f6cc1b2f845d2ca1eba53336f64597c49e62.zip
test: stop two tests depending on the machine they run on
Both are the same class of defect: a test that reads real machine state and so passes or fails on circumstance rather than on the code under test. Item 38. Every MainWindow a test builds constructed its SyncMonitor on the live /proc/locks, so a window observed the machine's actual sync state and the sync-button assertion failed whenever the user's cron sync happened to be running. Cron fires every ten minutes and a run lasts ~35s, which is roughly 6% of runs, and it read as flakiness. SyncMonitor already took an injectable locks path for exactly this; MainWindow did not expose it. It does now, as a test seam rather than a config key: /proc/locks is not something a user would set, and a wrong value silently disables background sync detection instead of failing loudly. The monitor is still constructed and started, per the item's own constraint. Only the table it reads is redirected, to an empty file in the test's own temporary directory. Item 46. uiStateSurvivesARestart asserted a 940px width, and the offscreen platform reports an 800x800 screen. restoreGeometry() clamps to the available area, so the width came back as 798 while the 620 height, which fits, restored untouched. That asymmetry was the tell that persistence was fine and the test was wrong. The size is now 640x560 and carries no meaning beyond differing from the default. Verified by reproducing the original conditions rather than by waiting for them: the suite run under flock -n /tmp/mbsync.lock fails item 38's assertion with the seam bypassed and passes with it in place, and item 46 now passes under offscreen where it failed. One dud mutation is recorded in the backlog, writing an unparseable line into the injected lock table does not fail the test, because lockHeldIn() correctly finds no lock in it. Suite: 15/15 offscreen with the lock held, and green on Wayland except the pre-existing querycompleter screenshot flake, which fails to grab under Wayland and passes offscreen.
Diffstat (limited to 'tests/test_mainwindow.cpp')
-rw-r--r--tests/test_mainwindow.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/tests/test_mainwindow.cpp b/tests/test_mainwindow.cpp
index c409d1a..6a4f903 100644
--- a/tests/test_mainwindow.cpp
+++ b/tests/test_mainwindow.cpp
@@ -233,7 +233,11 @@ void TestMainWindow::uiStateSurvivesARestart()
QStandardPaths::setTestModeEnabled(true);
QFile::remove(MainWindow::uiStatePath());
- const QSize resized(940, 620);
+ // Must fit the smallest screen this ever runs against: the offscreen
+ // platform reports 800x800, and restoreGeometry() clamps to the available
+ // area, so a 940px width came back as 798 and failed only under offscreen.
+ // The number carries no meaning beyond differing from the default size.
+ const QSize resized(640, 560);
{
const Config config;
MainWindow window(config);
@@ -995,6 +999,17 @@ void TestMainWindow::theSyncButtonIsDisabledWhileABackgroundSyncHoldsTheLock()
s.setValue(QStringLiteral("sync/command"), QStringLiteral("/bin/true"));
}
+ // An empty lock table, so construction observes no sync. Against the real
+ // /proc/locks this assertion fails whenever the user's cron sync happens to
+ // be running: cron fires every ten minutes and a run lasts ~35s, so roughly
+ // 6% of runs landed inside one and the failure looked like flakiness.
+ const QString locks = dir.filePath(QStringLiteral("locks"));
+ {
+ QFile f(locks);
+ QVERIFY(f.open(QIODevice::WriteOnly));
+ }
+ MainWindow::setLocksPathForTesting(locks);
+
Config config;
config.load(conf);
MainWindow window(config);
@@ -1014,6 +1029,11 @@ void TestMainWindow::theSyncButtonIsDisabledWhileABackgroundSyncHoldsTheLock()
SyncMonitor::State::Idle));
QVERIFY2(button->isEnabled(),
"the sync button was not re-enabled after the background sync");
+
+ // The override is process-wide, and QTemporaryDir takes the file with it at
+ // the end of this scope: leaving it set would point every later window at a
+ // path that no longer exists.
+ MainWindow::setLocksPathForTesting(QStringLiteral("/proc/locks"));
}
void TestMainWindow::anUnobservableLockTableLeavesTheSyncButtonUsable()