in glean-core/android/src/main/java/mozilla/telemetry/glean/testing/GleanTestRule.kt [48:115]
override fun starting(description: Description?) {
// We're using the WorkManager in a bunch of places, and Glean will crash
// in tests without this line. Let's simply put it here.
WorkManagerTestInitHelper.initializeTestWorkManager(context)
/**
* Always skip the first metrics ping, which would otherwise be overdue.
* Tests should explicitly destroy Glean and recreate it to test the metrics ping scheduler.
* This is the same as `delayMetricsPing` from `TestUtils.kt`,
* but now part of the publicly available test rule.
*/
// Set the current system time to a known datetime.
val fakeNow = Calendar.getInstance()
fakeNow.clear()
@Suppress("MagicNumber") // it's a fixed date only used in tests.
fakeNow.set(2015, 6, 11, 2, 0, 0)
SystemClock.setCurrentTimeMillis(fakeNow.timeInMillis)
// Set the last sent date to yesterday.
val buildInfo = BuildInfo(versionCode = "0.0.1", versionName = "0.0.1", buildDate = Calendar.getInstance())
val mps = MetricsPingScheduler(context, buildInfo)
mps.updateSentDate(getISOTimeString(fakeNow, truncateTo = TimeUnit.DAY))
PingType<NoReasonCodes>(
name = "store1",
includeClientId = true,
sendIfEmpty = false,
preciseTimestamps = true,
includeInfoSections = true,
enabled = true,
schedulesPings = emptyList(),
reasonCodes = emptyList(),
followsCollectionEnabled = true,
uploaderCapabilities = emptyList(),
)
PingType<NoReasonCodes>(
name = "store2",
includeClientId = true,
sendIfEmpty = false,
preciseTimestamps = true,
includeInfoSections = true,
enabled = true,
schedulesPings = emptyList(),
reasonCodes = emptyList(),
followsCollectionEnabled = true,
uploaderCapabilities = emptyList(),
)
PingType<NoReasonCodes>(
name = "store3",
includeClientId = true,
sendIfEmpty = false,
preciseTimestamps = true,
includeInfoSections = true,
enabled = true,
schedulesPings = emptyList(),
reasonCodes = emptyList(),
followsCollectionEnabled = true,
uploaderCapabilities = emptyList(),
)
Glean.resetGlean(
context = context,
config = configToUse,
clearStores = true,
)
}