로그아웃 즉시 처리 · 푸시 토큰 정리 순서
This commit is contained in:
@@ -1570,6 +1570,58 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test('정리가 끝나기 전 로그인하면 구독은 정리 완료 뒤에 호출된다', () async {
|
||||
final db = await _seed();
|
||||
final transport = _FakeTransport()..gate = Completer<void>();
|
||||
final push = PushMessaging(backend: _backend(db), transport: transport);
|
||||
final cleanup = push.clearOnSignOut(); // 기다리지 않는다
|
||||
final sync = push.syncTopics(PushTopic.defaults);
|
||||
await Future<void>.delayed(const Duration(milliseconds: 20));
|
||||
expect(transport.subscribed, isEmpty);
|
||||
transport.gate!.complete();
|
||||
await Future.wait([cleanup, sync]);
|
||||
expect(transport.subscribed, isNotEmpty);
|
||||
// 정리의 해지(구분 수만큼)가 모두 끝난 뒤에야 첫 구독이 나간다.
|
||||
expect(
|
||||
transport.log.indexOf('sub'),
|
||||
greaterThanOrEqualTo(PushTopic.values.length),
|
||||
);
|
||||
});
|
||||
|
||||
test('정리가 실패해도 로그인 구독은 진행된다', () async {
|
||||
final db = await _seed();
|
||||
final transport = _FakeTransport()..failUnsubscribe = true;
|
||||
final push = PushMessaging(backend: _backend(db), transport: transport);
|
||||
await push.clearOnSignOut(); // 던지지 않는다
|
||||
transport.failUnsubscribe = false;
|
||||
await push.syncTopics(PushTopic.defaults);
|
||||
expect(transport.subscribed, isNotEmpty);
|
||||
});
|
||||
|
||||
test('정리가 멈추면 상한 뒤 구독을 진행한다', () async {
|
||||
final db = await _seed();
|
||||
final transport = _FakeTransport()..gate = Completer<void>();
|
||||
final push = PushMessaging(backend: _backend(db), transport: transport);
|
||||
final old = PushMessaging.pendingClearTimeout;
|
||||
PushMessaging.pendingClearTimeout = const Duration(milliseconds: 50);
|
||||
addTearDown(() => PushMessaging.pendingClearTimeout = old);
|
||||
unawaited(push.clearOnSignOut());
|
||||
await Future<void>.delayed(const Duration(milliseconds: 10));
|
||||
transport.gate = null; // 이후 호출은 막지 않는다
|
||||
await push.syncTopics(PushTopic.defaults);
|
||||
expect(transport.subscribed, isNotEmpty);
|
||||
});
|
||||
|
||||
test('토큰 제거가 멈춰도 상한 뒤 clearOnSignOut 이 끝난다', () async {
|
||||
final db = await _seed();
|
||||
final transport = _FakeTransport()..tokenGate = Completer<String?>();
|
||||
final push = PushMessaging(backend: _backend(db), transport: transport);
|
||||
final old = PushMessaging.tokenRemoveTimeout;
|
||||
PushMessaging.tokenRemoveTimeout = const Duration(milliseconds: 50);
|
||||
addTearDown(() => PushMessaging.tokenRemoveTimeout = old);
|
||||
await push.clearOnSignOut().timeout(const Duration(seconds: 2));
|
||||
});
|
||||
|
||||
test('팬덤 소속이 없으면 아무 토픽도 건드리지 않는다', () async {
|
||||
final db = await _seed();
|
||||
await db.doc('users/$_uid').set({'uid': _uid, 'fandomId': ''});
|
||||
@@ -1605,6 +1657,10 @@ void main() {
|
||||
final class _FakeTransport implements PushTransport {
|
||||
final List<String> subscribed = [];
|
||||
final List<String> unsubscribed = [];
|
||||
final List<String> log = [];
|
||||
Completer<void>? gate;
|
||||
bool failUnsubscribe = false;
|
||||
Completer<String?>? tokenGate;
|
||||
|
||||
@override
|
||||
Future<AuthorizationStatus> requestPermission() async =>
|
||||
@@ -1615,17 +1671,24 @@ final class _FakeTransport implements PushTransport {
|
||||
AuthorizationStatus.authorized;
|
||||
|
||||
@override
|
||||
Future<String?> getToken() async => 'fake-token';
|
||||
Future<String?> getToken() async => tokenGate?.future ?? 'fake-token';
|
||||
|
||||
@override
|
||||
Stream<String> get onTokenRefresh => const Stream<String>.empty();
|
||||
|
||||
@override
|
||||
Future<void> subscribeToTopic(String topic) async => subscribed.add(topic);
|
||||
Future<void> subscribeToTopic(String topic) async {
|
||||
log.add('sub');
|
||||
subscribed.add(topic);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> unsubscribeFromTopic(String topic) async =>
|
||||
unsubscribed.add(topic);
|
||||
Future<void> unsubscribeFromTopic(String topic) async {
|
||||
await gate?.future;
|
||||
if (failUnsubscribe) throw Exception('offline');
|
||||
log.add('unsub');
|
||||
unsubscribed.add(topic);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<RemoteMessage?> getInitialMessage() async => null;
|
||||
|
||||
@@ -1010,14 +1010,15 @@ void main() {
|
||||
///
|
||||
/// 이 배선이 없던 동안 모달은 「09-10 회차에 연결합니다」 안내만 띄우고 세션을
|
||||
/// 그대로 두었다. 화면만 보면 로그아웃된 것처럼 보이지 않아 결함이 드러나지 않는다.
|
||||
testWidgets('푸시 정리가 실패해도 첫 확인에 로그아웃된다 (10/6 실기기)', (tester) async {
|
||||
testWidgets('로그아웃은 푸시 토큰 제거 뒤에 세션을 끊는다 (10/6 r4)', (tester) async {
|
||||
final session = _LogoutSession(
|
||||
const AuthAccount(uid: 'u1', provider: SocialProvider.google),
|
||||
);
|
||||
final auth = AuthRepository(providers: const [], session: session, releaseMode: true);
|
||||
final push = _OrderPush(session);
|
||||
await pumpWide(
|
||||
tester,
|
||||
SettingsScreen(repository: SampleMyRepository(), auth: auth, push: _FailingPush()),
|
||||
SettingsScreen(repository: SampleMyRepository(), auth: auth, push: push),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.scrollUntilVisible(find.text('로그아웃'), 220, scrollable: find.byType(Scrollable).first);
|
||||
@@ -1025,31 +1026,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.widgetWithText(FilledButton, '로그아웃'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(session.signOutCalls, 1);
|
||||
auth.dispose();
|
||||
await session.close();
|
||||
});
|
||||
|
||||
testWidgets('푸시 정리가 멈춰도 상한 안에 첫 확인으로 로그아웃된다 — 확인 버튼은 진행 중 (10/6 r3)', (tester) async {
|
||||
final session = _LogoutSession(
|
||||
const AuthAccount(uid: 'u1', provider: SocialProvider.google),
|
||||
);
|
||||
final auth = AuthRepository(providers: const [], session: session, releaseMode: true);
|
||||
await pumpWide(
|
||||
tester,
|
||||
SettingsScreen(repository: SampleMyRepository(), auth: auth, push: _HangingPush()),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.scrollUntilVisible(find.text('로그아웃'), 220, scrollable: find.byType(Scrollable).first);
|
||||
await tester.tap(find.text('로그아웃'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.widgetWithText(FilledButton, '로그아웃'));
|
||||
await tester.pump();
|
||||
// 정리가 도는 동안 확인 버튼은 진행 중 표시다.
|
||||
expect(find.byType(CircularProgressIndicator), findsOneWidget);
|
||||
expect(session.signOutCalls, 0);
|
||||
await tester.pump(const Duration(seconds: 4));
|
||||
await tester.pumpAndSettle();
|
||||
expect(push.signOutsAtClear, 0);
|
||||
expect(session.signOutCalls, 1);
|
||||
auth.dispose();
|
||||
await session.close();
|
||||
@@ -1090,19 +1067,14 @@ void main() {
|
||||
});
|
||||
}
|
||||
|
||||
/// 푸시 정리가 실패하는 경계 — 토픽 해제 · 토큰 쓰기가 네트워크 오류로 던진다.
|
||||
class _FailingPush implements PushMessaging {
|
||||
@override
|
||||
Future<void> clearOnSignOut() async => throw Exception('offline');
|
||||
/// 토큰 제거가 불린 시점의 signOut 횟수를 남긴다 — 0 이어야 제거가 먼저다.
|
||||
class _OrderPush implements PushMessaging {
|
||||
_OrderPush(this._session);
|
||||
final _LogoutSession _session;
|
||||
int? signOutsAtClear;
|
||||
|
||||
@override
|
||||
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
||||
}
|
||||
|
||||
/// 푸시 정리가 응답 없이 멈추는 경계 — 토픽 해제가 끝나지 않는다.
|
||||
class _HangingPush implements PushMessaging {
|
||||
@override
|
||||
Future<void> clearOnSignOut() => Completer<void>().future;
|
||||
Future<void> clearOnSignOut() async => signOutsAtClear = _session.signOutCalls;
|
||||
|
||||
@override
|
||||
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
||||
|
||||
Reference in New Issue
Block a user