mirror of
https://github.com/wger-project/flutter.git
synced 2026-11-28 17:08:29 +01:00
Let a probe misfire not restart the stall detection
This commit is contained in:
@@ -120,7 +120,9 @@ class SyncStreamWatchdog {
|
||||
}
|
||||
_offline = value;
|
||||
if (value) {
|
||||
_cancelTimer();
|
||||
// A running timer deliberately survives: the probe misfires while a
|
||||
// large download saturates the line, and cancelling here would let
|
||||
// those misfires restart the detection over and over.
|
||||
stalled.value = false;
|
||||
}
|
||||
}
|
||||
@@ -143,6 +145,11 @@ class SyncStreamWatchdog {
|
||||
|
||||
void _onTimeout() {
|
||||
_timer = null;
|
||||
// Nothing to report while plain requests fail as well; the next status
|
||||
// event re-arms once the backend answers again.
|
||||
if (_offline) {
|
||||
return;
|
||||
}
|
||||
stalled.value = true;
|
||||
|
||||
if (_lastError case final error?) {
|
||||
|
||||
@@ -191,7 +191,25 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
test('going offline cancels a pending timer and clears the flag', () {
|
||||
test('a probe misfiring under load does not restart the detection', () {
|
||||
fakeAsync((async) {
|
||||
// The reachability probe times out while a large download saturates
|
||||
// the line and recovers right after. If that restarted the clock, the
|
||||
// watchdog would never reach its timeout on exactly the connection it
|
||||
// is meant to flag.
|
||||
watchdog.onStatus(buildSyncStatus(connecting: true));
|
||||
async.elapse(watchdog.timeout - const Duration(seconds: 10));
|
||||
|
||||
watchdog.offline = true;
|
||||
watchdog.offline = false;
|
||||
watchdog.onStatus(buildSyncStatus(connecting: true));
|
||||
|
||||
async.elapse(const Duration(seconds: 11));
|
||||
expect(watchdog.stalled.value, isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
test('going offline clears the flag and reports nothing further', () {
|
||||
fakeAsync((async) {
|
||||
watchdog.onStatus(buildSyncStatus(connecting: true));
|
||||
async.elapse(watchdog.timeout);
|
||||
|
||||
Reference in New Issue
Block a user