Skip to content

Commit

Permalink
Download counts: properly handle case with non-existing package (#7973)
Browse files Browse the repository at this point in the history
  • Loading branch information
szakarias committed Aug 23, 2024
1 parent f9ba483 commit f336752
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/lib/service/download_counts/sync_download_counts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,10 @@ Future<bool> processDownloadCounts(
(await packageBackend.lookupModeratedPackage(package)) == null) {
_logger.severe(
'Package $package appeared in download counts data for file '
'$downloadCountsFileName'
'$downloadCountsFileName but does not exist.\n'
'Error: $e');
hasPartiallyFailedLines = true;
return;
} // else {
// The package is either invisible, tombstoned or has no versions.
// }
Expand Down
36 changes: 36 additions & 0 deletions app/test/service/download_counts/download_counts_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,42 @@ void main() {
expect(neonCountData, isNull);
});

testWithProfile('with non-existing package', fn: () async {
final nextDate = DateTime.parse('2024-01-06');
final downloadCountsJsonFileNameJan6 =
'daily_download_counts/2024-01-06T00:00:00Z/data-000000000000.jsonl';
await generateFakeDownloadCounts(
downloadCountsJsonFileNameJan6,
path.join(
Directory.current.path,
'test',
'service',
'download_counts',
'fake_download_counts_data_non_existing_package.jsonl'));
bool succeeded;
final messages = <String>[];
final subscription = Logger.root.onRecord.listen((event) {
messages.add(event.message);
});
try {
succeeded = await processDownloadCounts(
downloadCountsJsonFileNameJan6, nextDate);
} finally {
await subscription.cancel();
}
expect(succeeded, false);
expect(messages.first, contains('Could not find `package "hest"`.'));
// We still process the lines that are possible
final countData =
await downloadCountsBackend.lookupDownloadCountData('neon');
expect(countData, isNotNull);
expect(countData!.newestDate, nextDate);

final hestCountData =
await downloadCountsBackend.lookupDownloadCountData('hest');
expect(hestCountData, isNull);
});

testWithProfile('file not present', fn: () async {
final nextDate = DateTime.parse('2024-01-06');
bool succeeded;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"package":"hest","total":"1","per_version":[{"version":"1.0.0","count":"1"},{"version":"1.2.0","count":"1"},{"version":"2.0.0-dev","count":"1"}]}
{"package":"neon","total":"1","per_version":[{"version":"1.0.0","count":"1"}]}

0 comments on commit f336752

Please sign in to comment.