merge(app): land foreground-list-refresh (run 157)
This commit is contained in:
@@ -80,6 +80,10 @@ class _PipelinesAppState extends State<PipelinesApp>
|
|||||||
/// list once; the run itself is then opened from its route.
|
/// list once; the run itself is then opened from its route.
|
||||||
int _runsRefresh = 0;
|
int _runsRefresh = 0;
|
||||||
|
|
||||||
|
/// Prevents duplicate resumed notifications from refreshing twice before
|
||||||
|
/// the next background transition starts another foreground visit.
|
||||||
|
bool _foregroundVisitHandled = false;
|
||||||
|
|
||||||
/// One run detail request from Search, delivered through the shell so the
|
/// One run detail request from Search, delivered through the shell so the
|
||||||
/// mounted run detail can resolve it once the named run's steps have loaded.
|
/// mounted run detail can resolve it once the named run's steps have loaded.
|
||||||
/// A field or artifact hit names no addressable URL of its own, so the request
|
/// A field or artifact hit names no addressable URL of its own, so the request
|
||||||
@@ -198,9 +202,29 @@ class _PipelinesAppState extends State<PipelinesApp>
|
|||||||
/// facts), so no screen re-subscribes on its own.
|
/// facts), so no screen re-subscribes on its own.
|
||||||
@override
|
@override
|
||||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||||
if (state != AppLifecycleState.resumed) return;
|
if (state != AppLifecycleState.resumed) {
|
||||||
if (!shouldReconnectOnForeground(_session.connection.kind)) return;
|
_foregroundVisitHandled = false;
|
||||||
unawaited(_session.retry());
|
return;
|
||||||
|
}
|
||||||
|
if (_foregroundVisitHandled) return;
|
||||||
|
_foregroundVisitHandled = true;
|
||||||
|
final connection = _session.connection.kind;
|
||||||
|
if (shouldReconnectOnForeground(connection)) {
|
||||||
|
unawaited(_session.retry());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (connection != ConnectionKind.connected) return;
|
||||||
|
|
||||||
|
// A return to the foreground refreshes only the visible list. Detail routes
|
||||||
|
// (including pipeline definitions and run visits) keep their current data.
|
||||||
|
final route = _delegate.route;
|
||||||
|
if (route.kind == AppRouteKind.pipelines &&
|
||||||
|
route.pipelineId == null &&
|
||||||
|
route.stageKey == null) {
|
||||||
|
setState(() => _pipelinesRefresh++);
|
||||||
|
} else if (route.kind == AppRouteKind.runs && route.runId == null) {
|
||||||
|
setState(() => _runsRefresh++);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A replaced socket drops the attention status baseline so the gap cannot
|
/// A replaced socket drops the attention status baseline so the gap cannot
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ List<String> types(FakeChannel channel) => <String>[
|
|||||||
(jsonDecode(frame as String) as Map<String, dynamic>)['type'] as String,
|
(jsonDecode(frame as String) as Map<String, dynamic>)['type'] as String,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
int countType(FakeChannel channel, String type) =>
|
||||||
|
types(channel).where((value) => value == type).length;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
tearDown(() {
|
tearDown(() {
|
||||||
WidgetsBinding.instance.handleAppLifecycleStateChanged(
|
WidgetsBinding.instance.handleAppLifecycleStateChanged(
|
||||||
@@ -100,21 +103,75 @@ void main() {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
testWidgets('foreground resume does not churn a still-connected socket', (
|
testWidgets('foreground resume refreshes the visible Pipelines list once', (
|
||||||
tester,
|
tester,
|
||||||
) async {
|
) async {
|
||||||
final channel = FakeChannel()..readyCompleter.complete();
|
final channel = FakeChannel()..readyCompleter.complete();
|
||||||
final client = PipelinesClient(channelFactory: (_) => channel);
|
final client = PipelinesClient(channelFactory: (_) => channel);
|
||||||
await pumpApp(tester, provider: routeProvider(), client: client);
|
await pumpApp(tester, provider: routeProvider(), client: client);
|
||||||
await replyPipelines(tester, channel, PipelineFixture());
|
await replyPipelines(tester, channel, PipelineFixture());
|
||||||
|
final before = countType(channel, 'list_pipelines');
|
||||||
expect(types(channel).where((type) => type == 'subscribe'), hasLength(1));
|
expect(types(channel).where((type) => type == 'subscribe'), hasLength(1));
|
||||||
|
|
||||||
await resume(tester);
|
await resume(tester);
|
||||||
|
|
||||||
|
expect(countType(channel, 'list_pipelines'), before + 1);
|
||||||
expect(types(channel).where((type) => type == 'subscribe'), hasLength(1));
|
expect(types(channel).where((type) => type == 'subscribe'), hasLength(1));
|
||||||
expect(client.state.kind, ConnectionKind.connected);
|
expect(client.state.kind, ConnectionKind.connected);
|
||||||
|
|
||||||
await tester.pumpWidget(const SizedBox.shrink());
|
await tester.pumpWidget(const SizedBox.shrink());
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('foreground resume refreshes the visible Runs list once', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
final channel = FakeChannel()..readyCompleter.complete();
|
||||||
|
final provider = PlatformRouteInformationProvider(
|
||||||
|
initialRouteInformation: RouteInformation(uri: Uri.parse('/runs')),
|
||||||
|
);
|
||||||
|
addTearDown(provider.dispose);
|
||||||
|
final client = PipelinesClient(channelFactory: (_) => channel);
|
||||||
|
await pumpApp(tester, provider: provider, client: client);
|
||||||
|
await waitForRequest(tester, channel, 'list_runs');
|
||||||
|
final initialRuns = pipelineRequest(channel, 'list_runs')!;
|
||||||
|
channel.incoming.add(
|
||||||
|
jsonEncode({
|
||||||
|
'id': initialRuns['id'],
|
||||||
|
'type': 'runs',
|
||||||
|
'runs': PipelineFixture().runs,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
await tester.pump();
|
||||||
|
final before = countType(channel, 'list_runs');
|
||||||
|
|
||||||
|
await resume(tester);
|
||||||
|
|
||||||
|
expect(countType(channel, 'list_runs'), before + 1);
|
||||||
|
expect(countType(channel, 'subscribe'), 1);
|
||||||
|
await tester.pumpWidget(const SizedBox.shrink());
|
||||||
|
await tester.pump();
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('foreground resume does not refresh an open run detail', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
final channel = FakeChannel()..readyCompleter.complete();
|
||||||
|
final provider = routeProvider();
|
||||||
|
final client = PipelinesClient(channelFactory: (_) => channel);
|
||||||
|
await pumpApp(tester, provider: provider, client: client);
|
||||||
|
await replyPipelines(tester, channel, PipelineFixture());
|
||||||
|
provider.routerReportsNewRouteInformation(
|
||||||
|
RouteInformation(uri: Uri.parse('/runs/1')),
|
||||||
|
type: RouteInformationReportingType.navigate,
|
||||||
|
);
|
||||||
|
await tester.pump();
|
||||||
|
final before = countType(channel, 'list_runs');
|
||||||
|
|
||||||
|
await resume(tester);
|
||||||
|
|
||||||
|
expect(countType(channel, 'list_runs'), before);
|
||||||
|
await tester.pumpWidget(const SizedBox.shrink());
|
||||||
|
await tester.pump();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user