Пример #1
0
        public void TestLabeledBooleanMetricType()
        {
            BooleanMetricType booleanMetric = new BooleanMetricType(
                disabled: false,
                category: "telemetry",
                lifetime: Lifetime.Application,
                name: "labeled_boolean_metric",
                sendInPings: new string[] { "metrics" }
                );

            var labeledBooleanMetric = new LabeledMetricType <BooleanMetricType>(
                disabled: false,
                category: "telemetry",
                lifetime: Lifetime.Application,
                name: "labeled_boolean_metric",
                sendInPings: new string[] { "metrics" },
                submetric: booleanMetric
                );

            labeledBooleanMetric["label1"].Set(false);
            labeledBooleanMetric["label2"].Set(true);

            Assert.False(labeledBooleanMetric["label1"].TestGetValue());
            Assert.True(labeledBooleanMetric["label2"].TestGetValue());
        }
Пример #2
0
        public void SendCustomPingsWithSnakeCase()
        {
            PingType <NoReasonCodes> customPing = new PingType <NoReasonCodes>(
                name: "custom_ping",
                includeClientId: true,
                sendIfEmpty: false,
                reasonCodes: null
                );

            BooleanMetricType sampleMetric = new BooleanMetricType(
                disabled: false,
                category: "test",
                lifetime: Lifetime.Ping,
                name: "boolean_metric",
                sendInPings: new string[] { "custom_ping" }
                );

            sampleMetric.Set(true);
            Assert.True(sampleMetric.TestHasValue());

            customPing.Submit();

            MockUploader.UploadRequest request = mockUploader.GetPendingUpload();
            Assert.Equal("custom_ping", request.docType);

            // Check that we have a non-null client id.
            JsonDocument jsonPayload = JsonDocument.Parse(request.payload);
            JsonElement  root        = jsonPayload.RootElement;

            Assert.NotNull(root.GetProperty("client_info").GetProperty("client_id").GetString());

            // TODO: Check the ping schema.
            // checkPingSchema(pingJson)
        }
Пример #3
0
        public void EnsureInvalidLabelsOnLabeledBooleanGoToOther()
        {
            BooleanMetricType booleanMetric = new BooleanMetricType(
                disabled: false,
                category: "telemetry",
                lifetime: Lifetime.Application,
                name: "labeled_boolean_metric",
                sendInPings: new string[] { "metrics" }
                );

            var labeledBooleanMetric = new LabeledMetricType <BooleanMetricType>(
                disabled: false,
                category: "telemetry",
                lifetime: Lifetime.Application,
                name: "labeled_boolean_metric",
                sendInPings: new string[] { "metrics" },
                submetric: booleanMetric
                );

            labeledBooleanMetric["notSnakeCase"].Set(true);
            labeledBooleanMetric[""].Set(true);
            labeledBooleanMetric["with/slash"].Set(true);
            labeledBooleanMetric["this_string_has_more_than_thirty_characters"].Set(true);

            Assert.Equal(
                4,
                labeledBooleanMetric.TestGetNumRecordedErrors(
                    ErrorType.InvalidLabel
                    )
                );
            Assert.True(
                labeledBooleanMetric["__other__"].TestGetValue()
                );
        }
Пример #4
0
        public void SendCustomPingsWithAnUnknownNameNoOp()
        {
            const string unknownPingName = "unknown";

            Assert.False(GleanInstance.TestHasPingType(unknownPingName));

            BooleanMetricType sampleMetric = new BooleanMetricType(
                disabled: false,
                category: "test",
                lifetime: Lifetime.Ping,
                name: "boolean_metric",
                sendInPings: new string[] { unknownPingName }
                );

            sampleMetric.Set(true);
            Assert.True(sampleMetric.TestHasValue());

            GleanInstance.SubmitPingByName(unknownPingName);

            // We don't expect any ping to be sent.
            Assert.Equal(0, mockUploader.GetUploadRequestCount());
        }