fix(market): recover by itself when the shared connection comes up
Fresh installs could sit on 'can't reach the servers' forever: the offers cubit captured the transport once at build time, the shared connection only retried on a connectivity CHANGE, and a silently-filtered relay could stall the pool for minutes. - SocialConnection: retry with backoff after a failed attempt while started and not knowingly offline (injectable schedule for tests) - OffersCubit: follow connection.sessions, re-attach the transport and re-run the last discovery on (re)connect; announce drops via connectionEpoch - market _init: record the wanted area on the cubit even while offline - NostrOfferTransport.discoverPage: sort a copy (channel lists may be unmodifiable)
This commit is contained in:
parent
981cf10048
commit
8a7dc8d3dc
6 changed files with 273 additions and 9 deletions
|
|
@ -45,11 +45,13 @@ void main() {
|
|||
required List<FakeChannel> opened,
|
||||
Stream<bool>? online,
|
||||
bool Function()? fail,
|
||||
List<Duration>? retrySchedule,
|
||||
}) =>
|
||||
SocialConnection(
|
||||
social: social,
|
||||
settings: settings,
|
||||
online: online,
|
||||
retrySchedule: retrySchedule,
|
||||
open: (_) async {
|
||||
if (fail?.call() ?? false) throw StateError('unreachable');
|
||||
final ch = FakeChannel();
|
||||
|
|
@ -106,6 +108,69 @@ void main() {
|
|||
await online.close();
|
||||
});
|
||||
|
||||
test(
|
||||
'started connection retries by itself after a failed first attempt, '
|
||||
'without any connectivity event', () async {
|
||||
// The fresh-install case: device online the whole time, but the very first
|
||||
// connect fails (cold DNS/TLS). The connectivity stream never fires, so
|
||||
// only the backoff retry can bring the market up without a manual Retry.
|
||||
final opened = <FakeChannel>[];
|
||||
var down = true;
|
||||
final conn = make(
|
||||
opened: opened,
|
||||
online: const Stream.empty(), // connectivity never speaks
|
||||
fail: () => down,
|
||||
retrySchedule: const [Duration(milliseconds: 5)],
|
||||
);
|
||||
final emitted = <SocialSession?>[];
|
||||
conn.sessions.listen(emitted.add);
|
||||
|
||||
conn.start();
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
expect(conn.current, isNull); // first attempt failed
|
||||
|
||||
down = false; // network path recovers
|
||||
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||
expect(conn.current, isNotNull, reason: 'backoff retry reconnected');
|
||||
expect(opened, hasLength(1));
|
||||
expect(emitted.last, isNotNull, reason: 'recovery announced on sessions');
|
||||
|
||||
await conn.dispose();
|
||||
});
|
||||
|
||||
test('a plain session() failure schedules no retry when never started',
|
||||
() async {
|
||||
// Widget tests build cubits against an un-started connection; a failed
|
||||
// one-shot session() must not leave a pending retry timer behind.
|
||||
final opened = <FakeChannel>[];
|
||||
final conn = make(
|
||||
opened: opened,
|
||||
fail: () => true,
|
||||
retrySchedule: const [Duration(milliseconds: 5)],
|
||||
);
|
||||
expect(await conn.session(), isNull);
|
||||
await Future<void>.delayed(const Duration(milliseconds: 50));
|
||||
expect(opened, isEmpty); // no background retry fired
|
||||
await conn.dispose();
|
||||
});
|
||||
|
||||
test('dispose cancels a pending backoff retry', () async {
|
||||
final opened = <FakeChannel>[];
|
||||
var down = true;
|
||||
final conn = make(
|
||||
opened: opened,
|
||||
online: const Stream.empty(),
|
||||
fail: () => down,
|
||||
retrySchedule: const [Duration(milliseconds: 20)],
|
||||
);
|
||||
conn.start();
|
||||
await Future<void>.delayed(Duration.zero); // first attempt fails
|
||||
await conn.dispose(); // cancels the scheduled retry
|
||||
down = false;
|
||||
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||
expect(opened, isEmpty, reason: 'no reconnect after dispose');
|
||||
});
|
||||
|
||||
test('returns null when the relay is unreachable, and retries later',
|
||||
() async {
|
||||
final opened = <FakeChannel>[];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue