Skip to content

Commit e722e19

Browse files
committed
Fix tests
1 parent e422d12 commit e722e19

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

app/lib/package/api_export/api_exporter.dart

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
import 'dart:async';
66

7+
import 'package:_pub_shared/data/package_api.dart';
78
import 'package:clock/clock.dart';
89
import 'package:gcloud/service_scope.dart' as ss;
910
import 'package:gcloud/storage.dart';
1011
import 'package:logging/logging.dart';
1112
import 'package:pub_dev/service/security_advisories/backend.dart';
13+
import 'package:pub_dev/shared/exceptions.dart';
1214
import 'package:pub_dev/shared/parallel_foreach.dart';
1315

1416
import '../../search/backend.dart';
@@ -164,9 +166,20 @@ class ApiExporter {
164166
Future<void> synchronizePackage(String package) async {
165167
_log.info('synchronizePackage("$package")');
166168

167-
// TODO: Handle the case where [package] is deleted or invisible!
168-
// TODO: We may need to delete the package, but only if it's not too recent!
169-
final versionListing = await packageBackend.listVersions(package);
169+
final PackageData versionListing;
170+
try {
171+
versionListing = await packageBackend.listVersions(package);
172+
} on NotFoundException {
173+
// Handle the case where package is moderated.
174+
final pkg = await packageBackend.lookupPackage(package);
175+
if (pkg != null && pkg.isNotVisible) {
176+
// We only delete the package if it is explicitly not visible.
177+
// If we can't find it, then it's safer to assume that it's a bug.
178+
await _api.package(package).delete();
179+
}
180+
return;
181+
}
182+
170183
// TODO: Consider skipping the cache when fetching security advisories
171184
final advisories = await securityAdvisoryBackend.listAdvisoriesResponse(
172185
package,

app/test/package/api_export/api_exporter_test.dart

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:_pub_shared/data/admin_api.dart';
99
import 'package:_pub_shared/data/package_api.dart';
1010
import 'package:gcloud/storage.dart';
1111
import 'package:googleapis/storage/v1.dart' show DetailedApiRequestError;
12+
import 'package:logging/logging.dart';
1213
import 'package:pub_dev/fake/backend/fake_auth_provider.dart';
1314
import 'package:pub_dev/package/api_export/api_exporter.dart';
1415
import 'package:pub_dev/shared/storage.dart';
@@ -23,6 +24,8 @@ import '../../shared/test_models.dart';
2324
import '../../shared/test_services.dart';
2425
import '../../task/fake_time.dart';
2526

27+
final _log = Logger('api_export.test');
28+
2629
final _testProfile = TestProfile(
2730
defaultUser: userAtPubDevEmail,
2831
packages: [
@@ -55,7 +58,6 @@ void main() {
5558
testWithFakeTime(
5659
'apiExporter.start()',
5760
testProfile: _testProfile,
58-
skip: 'Fix this test!',
5961
(fakeTime) async {
6062
await storageService.createBucket('bucket');
6163
final bucket = storageService.bucket('bucket');
@@ -68,7 +70,7 @@ void main() {
6870
await _testExportedApiSynchronization(
6971
fakeTime,
7072
bucket,
71-
() async => await fakeTime.elapse(hours: 3),
73+
() async => await fakeTime.elapse(minutes: 15),
7274
);
7375

7476
await apiExporter.stop();
@@ -81,7 +83,7 @@ Future<void> _testExportedApiSynchronization(
8183
Bucket bucket,
8284
Future<void> Function() synchronize,
8385
) async {
84-
// ## Existing package
86+
_log.info('## Existing package');
8587
{
8688
await synchronize();
8789

@@ -121,7 +123,7 @@ Future<void> _testExportedApiSynchronization(
121123
);
122124
}
123125

124-
// ## New package
126+
_log.info('## New package');
125127
{
126128
await importProfile(
127129
source: ImportSource.autoGenerated(),
@@ -167,7 +169,7 @@ Future<void> _testExportedApiSynchronization(
167169
);
168170
}
169171

170-
// ## New package version
172+
_log.info('## New package version');
171173
{
172174
await importProfile(
173175
source: ImportSource.autoGenerated(),
@@ -206,7 +208,7 @@ Future<void> _testExportedApiSynchronization(
206208
);
207209
}
208210

209-
// ## Discontinued flipped on
211+
_log.info('## Discontinued flipped on');
210212
{
211213
final api = await createFakeAuthPubApiClient(email: userAtPubDevEmail);
212214
await api.setPackageOptions(
@@ -229,7 +231,7 @@ Future<void> _testExportedApiSynchronization(
229231
);
230232
}
231233

232-
// ## Discontinued flipped off
234+
_log.info('## Discontinued flipped off');
233235
{
234236
final api = await createFakeAuthPubApiClient(email: userAtPubDevEmail);
235237
await api.setPackageOptions(
@@ -251,7 +253,7 @@ Future<void> _testExportedApiSynchronization(
251253
);
252254
}
253255

254-
// ## Version retracted
256+
_log.info('## Version retracted');
255257
{
256258
final api = await createFakeAuthPubApiClient(email: userAtPubDevEmail);
257259
await api.setVersionOptions(
@@ -274,7 +276,7 @@ Future<void> _testExportedApiSynchronization(
274276
);
275277
}
276278

277-
// ## Version moderated
279+
_log.info('## Version moderated');
278280
{
279281
// Elapse time before moderating package, because exported-api won't delete
280282
// recently created files as a guard against race conditions.
@@ -315,7 +317,7 @@ Future<void> _testExportedApiSynchronization(
315317
);
316318
}
317319

318-
// ## Version reinstated
320+
_log.info('## Version reinstated');
319321
{
320322
final adminApi = createPubApiClient(
321323
authToken: createFakeServiceAccountToken(email: '[email protected]'),
@@ -352,7 +354,7 @@ Future<void> _testExportedApiSynchronization(
352354
);
353355
}
354356

355-
// ## Package moderated
357+
_log.info('## Package moderated');
356358
{
357359
// Elapse time before moderating package, because exported-api won't delete
358360
// recently created files as a guard against race conditions.
@@ -387,7 +389,7 @@ Future<void> _testExportedApiSynchronization(
387389
);
388390
}
389391

390-
// ## Package reinstated
392+
_log.info('## Package reinstated');
391393
{
392394
final adminApi = createPubApiClient(
393395
authToken: createFakeServiceAccountToken(email: '[email protected]'),

0 commit comments

Comments
 (0)