Commit 594be627 authored by Michael Droettboom's avatar Michael Droettboom
Browse files

1587405: Allow recording the empty string list

parent e30b3071
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -122,6 +122,10 @@ object ErrorRecording {
            sendInPings = metricData.sendInPings
        )

        if (!errorMetric.testHasValue(usePingName)) {
            return 0
        } else {
            return errorMetric.testGetValue(usePingName)
        }
    }
}
+0 −11
Original line number Diff line number Diff line
@@ -133,17 +133,6 @@ internal open class StringListsStorageEngineImplementation(
            it.take(MAX_STRING_LENGTH)
        }

        // Record an error when attempting to record a zero-length list and return.
        if (stringList.count() == 0) {
            recordError(
                metricData,
                ErrorType.InvalidValue,
                "Attempt to set() an empty string list to ${metricData.identifier}",
                logger
            )
            return
        }

        if (stringList.count() > MAX_LIST_LENGTH_VALUE) {
            recordError(
                metricData,
+4 −8
Original line number Diff line number Diff line
@@ -203,7 +203,7 @@ class StringListsStorageEngineTest {
    }

    @Test
    fun `set() records an error and returns when passed an empty list`() {
    fun `set() doesn't record an error when passed an empty list`() {
        val metric = StringListMetricType(
            disabled = false,
            category = "telemetry",
@@ -214,14 +214,10 @@ class StringListsStorageEngineTest {

        StringListsStorageEngine.set(metricData = metric, value = listOf())

        // If nothing was stored, then the snapshot should be null
        val snapshot = StringListsStorageEngine.getSnapshot(
            storeName = "store1",
            clearStore = false)
        assertNull("Empty list must not be stored", snapshot)
        assertEquals(listOf<String>(), metric.testGetValue())

        // Verify the error was recorded
        assertEquals(1, testGetNumRecordedErrors(metric, ErrorType.InvalidValue))
        // Verify the error was not recorded
        assertEquals(0, testGetNumRecordedErrors(metric, ErrorType.InvalidValue))
    }

    @Test