Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/lib/package/api_export/exported_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ final class ExportedPackage {
Future<void> garbageCollect(Set<String> allVersionNumbers) async {
await Future.wait([
..._owner._prefixes.map((prefix) async {
final pfx = '/api/archives/$_package-';
final pfx = prefix + '/api/archives/$_package-';
await _owner._listBucket(prefix: pfx, delimiter: '', (item) async {
assert(item.isObject);
if (!item.name.endsWith('.tar.gz')) {
Expand Down
47 changes: 47 additions & 0 deletions app/test/package/api_export/exported_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,53 @@ void main() {
);
}
});

testWithFakeTime('ExportedApi.garbageCollect()', (fakeTime) async {
await storageService.createBucket('exported-api');
final bucket = storageService.bucket('exported-api');
final exportedApi = ExportedApi(storageService, bucket);

await exportedApi.package('retry').tarball('1.2.3').write([1, 2, 3]);

await exportedApi.package('retry').tarball('1.2.4').copyFrom(
bucket,
'latest/api/archives/retry-1.2.3.tar.gz',
);

// Files are present
expect(
await bucket.readBytes('latest/api/archives/retry-1.2.3.tar.gz'),
[1, 2, 3],
);
expect(
await bucket.readBytes('latest/api/archives/retry-1.2.4.tar.gz'),
[1, 2, 3],
);

// Nothing is GC'ed after 10 mins
fakeTime.elapseSync(minutes: 10);
await exportedApi.package('retry').garbageCollect({'1.2.3'});
expect(
await bucket.readBytes('latest/api/archives/retry-1.2.3.tar.gz'),
[1, 2, 3],
);
expect(
await bucket.readBytes('latest/api/archives/retry-1.2.4.tar.gz'),
[1, 2, 3],
);

// Something is GC'ed after 2 days
fakeTime.elapseSync(days: 2);
await exportedApi.package('retry').garbageCollect({'1.2.3'});
expect(
await bucket.readBytes('latest/api/archives/retry-1.2.3.tar.gz'),
[1, 2, 3],
);
expect(
await bucket.readBytes('latest/api/archives/retry-1.2.4.tar.gz'),
isNull,
);
});
}

extension on Bucket {
Expand Down
Loading