From 32d66e7be24fea74958a1aa5dc36066fdd38987d Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Mon, 28 Oct 2024 16:51:27 -0400 Subject: [PATCH] feat: print message directing users to github issue if windows download takes too long (#2588) --- .../src/commands/patch/android_patcher.dart | 23 +++++++++++++ .../commands/patch/android_patcher_test.dart | 34 +++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/packages/shorebird_cli/lib/src/commands/patch/android_patcher.dart b/packages/shorebird_cli/lib/src/commands/patch/android_patcher.dart index 744bdea4..d0b86a2d 100644 --- a/packages/shorebird_cli/lib/src/commands/patch/android_patcher.dart +++ b/packages/shorebird_cli/lib/src/commands/patch/android_patcher.dart @@ -1,7 +1,9 @@ +import 'dart:async'; import 'dart:io'; import 'package:crypto/crypto.dart'; import 'package:io/io.dart'; +import 'package:mason_logger/mason_logger.dart'; import 'package:path/path.dart' as p; import 'package:shorebird_cli/src/archive_analysis/android_archive_differ.dart'; import 'package:shorebird_cli/src/artifact_builder.dart'; @@ -118,6 +120,7 @@ Looked in: required String appId, required int releaseId, required File releaseArtifact, + Duration downloadMessageTimeout = const Duration(minutes: 1), }) async { final releaseArtifacts = await codePushClientWrapper.getReleaseArtifacts( appId: appId, @@ -128,6 +131,24 @@ Looked in: final releaseArtifactPaths = {}; final numArtifacts = releaseArtifacts.length; + // Direct users to https://github.com/shorebirdtech/shorebird/issues/2532 + // until we can provide a better solution. + var artifactsDownloadCompleted = false; + unawaited( + Future.delayed(downloadMessageTimeout).then( + (_) { + if (artifactsDownloadCompleted) { + return; + } + logger.info( + ''' +It seems like your download is taking longer than expected. If you are on Windows, this is a known issue. +Please refer to ${link(uri: Uri.parse('https://github.com/shorebirdtech/shorebird/issues/2532'))} for potential workarounds.''', + ); + }, + ), + ); + for (final (i, releaseArtifact) in releaseArtifacts.entries.indexed) { try { final releaseArtifactFile = @@ -141,6 +162,8 @@ Looked in: } } + artifactsDownloadCompleted = true; + final patchArchsBuildDir = ArtifactManager.androidArchsDirectory( projectRoot: projectRoot, flavor: flavor, diff --git a/packages/shorebird_cli/test/src/commands/patch/android_patcher_test.dart b/packages/shorebird_cli/test/src/commands/patch/android_patcher_test.dart index 3ff0f969..51b2fa94 100644 --- a/packages/shorebird_cli/test/src/commands/patch/android_patcher_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/android_patcher_test.dart @@ -605,6 +605,40 @@ Looked in: expect(signatures, equals(expectedSignatures)); }); }); + + group('when artifacts download takes longer than provided timeout', () { + setUp(() { + when( + () => artifactManager.downloadWithProgressUpdates( + any(), + message: any(named: 'message'), + ), + ).thenAnswer((_) async { + await Future.delayed(const Duration(milliseconds: 100)); + return File(''); + }); + }); + + test('prints message directing users to github issue', () async { + await runWithOverrides( + () => patcher.createPatchArtifacts( + appId: 'appId', + releaseId: 0, + releaseArtifact: File('release.aab'), + downloadMessageTimeout: const Duration(milliseconds: 50), + ), + ); + + verify( + () => logger.info( + any( + that: contains( + 'https://github.com/shorebirdtech/shorebird/issues/2532'), + ), + ), + ).called(1); + }); + }); }); });