로그아웃 즉시 처리 · 푸시 토큰 정리 순서
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;
|
||||
|
||||
Reference in New Issue
Block a user