@@ -7,6 +7,7 @@ import 'dart:io';
77
88import 'package:gcloud/service_scope.dart' as ss;
99import 'package:logging/logging.dart' ;
10+ import 'package:meta/meta.dart' ;
1011import 'package:neat_periodic_task/neat_periodic_task.dart' ;
1112import 'package:pub_dev/service/download_counts/computations.dart' ;
1213
@@ -43,7 +44,9 @@ void setupPeriodTaskSchedulers() {
4344}
4445
4546/// List of periodic task schedulers.
46- List <NeatPeriodicTaskScheduler > createPeriodicTaskSchedulers () {
47+ List <NeatPeriodicTaskScheduler > createPeriodicTaskSchedulers ({
48+ @visibleForTesting bool isPostTestVerification = false ,
49+ }) {
4750 return [
4851 // Tries to send pending outgoing emails.
4952 _15mins (
@@ -177,19 +180,30 @@ List<NeatPeriodicTaskScheduler> createPeriodicTaskSchedulers() {
177180 ),
178181
179182 // Delete very old instances that have been abandoned
180- _daily (
181- name: 'garbage-collect-old-instances' ,
182- isRuntimeVersioned: false ,
183- task: () async => await deleteAbandonedInstances (
184- project: activeConfiguration.taskWorkerProject! ,
183+ //
184+ // NOTE: This task will use Google Cloud API to remove worker instances.
185+ // The client is not configured for fake environment, we should skip
186+ // this task in post-test verifications.
187+ // TODO: Write fake cloud abstractions to improve code coverage here.
188+ if (! isPostTestVerification)
189+ _daily (
190+ name: 'garbage-collect-old-instances' ,
191+ isRuntimeVersioned: false ,
192+ task: () async => await deleteAbandonedInstances (
193+ project: activeConfiguration.taskWorkerProject! ,
194+ ),
185195 ),
186- ),
187196
188- _daily (
189- name: 'sync-download-counts' ,
190- isRuntimeVersioned: false ,
191- task: syncDownloadCounts,
192- ),
197+ // Syncs download counts from storage bucket.
198+ //
199+ // NOTE: This task reports missing files in the logs.
200+ // TODO: Provide fake download data so that the task does not fail here.
201+ if (! isPostTestVerification)
202+ _daily (
203+ name: 'sync-download-counts' ,
204+ isRuntimeVersioned: false ,
205+ task: syncDownloadCounts,
206+ ),
193207
194208 _daily (
195209 name: 'compute-download-counts-30-days-totals' ,
@@ -203,11 +217,15 @@ List<NeatPeriodicTaskScheduler> createPeriodicTaskSchedulers() {
203217 task: countTopics,
204218 ),
205219
206- _daily (
207- name: 'sync-security-advisories' ,
208- isRuntimeVersioned: false ,
209- task: syncSecurityAdvisories,
210- ),
220+ // NOTE: This task will fetch the advisories from a public endpoint,
221+ // running it on every test is not worth it.
222+ // TODO: Consider injecting a fake data source for unit test.
223+ if (! isPostTestVerification)
224+ _daily (
225+ name: 'sync-security-advisories' ,
226+ isRuntimeVersioned: false ,
227+ task: syncSecurityAdvisories,
228+ ),
211229
212230 // Checks the Datastore integrity of the model objects.
213231 _weekly (
0 commit comments