|
| 1 | +package app.aaps.di.metro |
| 2 | + |
| 3 | +import app.aaps.implementation.maintenance.ImportExportPrefsImpl |
| 4 | +import app.aaps.implementation.receivers.KeepAliveWorker |
| 5 | +import app.aaps.implementation.scenes.SceneExpiryWorker |
| 6 | +import app.aaps.plugins.aps.loop.runningMode.RunningModeExpiryWorker |
| 7 | +import app.aaps.plugins.sync.nsclientV3.workers.DataSyncWorker |
| 8 | +import app.aaps.plugins.sync.nsclientV3.workers.LoadBgWorker |
| 9 | +import app.aaps.plugins.sync.nsclientV3.workers.LoadDeviceStatusWorker |
| 10 | +import app.aaps.plugins.sync.nsclientV3.workers.LoadFoodsWorker |
| 11 | +import app.aaps.plugins.sync.nsclientV3.workers.LoadLastModificationWorker |
| 12 | +import app.aaps.plugins.sync.nsclientV3.workers.LoadProfileStoreWorker |
| 13 | +import app.aaps.plugins.sync.nsclientV3.workers.LoadSettingsWorker |
| 14 | +import app.aaps.plugins.sync.nsclientV3.workers.LoadStatusWorker |
| 15 | +import app.aaps.plugins.sync.nsclientV3.workers.LoadTreatmentsWorker |
| 16 | +import app.aaps.plugins.sync.smsCommunicator.SmsCommunicatorPlugin |
| 17 | +import app.aaps.plugins.sync.xdrip.workers.XdripDataSyncWorker |
| 18 | +import app.aaps.workflow.PostCalculationWorker |
| 19 | +import app.aaps.workflow.PrepareGraphDataWorker |
| 20 | +import com.google.common.truth.Truth.assertThat |
| 21 | +import org.junit.jupiter.api.Test |
| 22 | + |
| 23 | +/** |
| 24 | + * The app-wide workers Metro builds, keyed by class. |
| 25 | + * |
| 26 | + * `MetroWorkerFactory` looks a worker up here and, on a miss, hands it to Hilt. That fallback is what |
| 27 | + * let workers move a few at a time - and it is also why a mistake here is silent: a worker that lost |
| 28 | + * its `@HiltWorker` but never reached this map is not a crash, it is a worker WorkManager can no longer |
| 29 | + * construct. The job simply stops running and nothing in the build says so. For the nsclientV3 loaders |
| 30 | + * that would mean Nightscout data quietly never syncing. |
| 31 | + * |
| 32 | + * Each worker registers itself - `@ContributesIntoMap` plus `@WorkerKey` on its nested |
| 33 | + * `@AssistedFactory` - so nothing central lists them any more, and this is the only place that states |
| 34 | + * which ones exist. Note the contribution targets `AppScope` while this map lives on a graph extension: |
| 35 | + * that it arrives here at all is the thing worth asserting. |
| 36 | + * |
| 37 | + * Same shape as `SourceGraphTest` does for the twelve source workers. |
| 38 | + */ |
| 39 | +class AppWorkersGraphTest { |
| 40 | + |
| 41 | + @Test |
| 42 | + fun `every app worker wired to Metro is registered under its own class`() { |
| 43 | + assertThat(testRoot().workersGraph.workerCreators.keys).containsExactly( |
| 44 | + RunningModeExpiryWorker::class, |
| 45 | + KeepAliveWorker::class, |
| 46 | + SceneExpiryWorker::class, |
| 47 | + ImportExportPrefsImpl.CsvExportWorker::class, |
| 48 | + ImportExportPrefsImpl.ApsResultExportWorker::class, |
| 49 | + // :workflow - recalculate and redraw the overview graph. |
| 50 | + PostCalculationWorker::class, |
| 51 | + PrepareGraphDataWorker::class, |
| 52 | + // :plugins:sync - the nine nsclientV3 loaders, plus xdrip and SMS. |
| 53 | + DataSyncWorker::class, |
| 54 | + LoadBgWorker::class, |
| 55 | + LoadDeviceStatusWorker::class, |
| 56 | + LoadFoodsWorker::class, |
| 57 | + LoadLastModificationWorker::class, |
| 58 | + LoadProfileStoreWorker::class, |
| 59 | + LoadSettingsWorker::class, |
| 60 | + LoadStatusWorker::class, |
| 61 | + LoadTreatmentsWorker::class, |
| 62 | + XdripDataSyncWorker::class, |
| 63 | + SmsCommunicatorPlugin.SmsCommunicatorWorker::class |
| 64 | + ) |
| 65 | + } |
| 66 | +} |
0 commit comments