-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add telemetry black box tests (#821)
This change required new testing command line flags to shorten the upload interval of metrics. This included the startup delay and initial upload interval of the metrics libraries. I also used this as an opportunity to make some improvements to the black box README. b/287248166 Change-Id: I469c6b3c4d4a34fb7d5770c5030e5cecb077b396
- Loading branch information
Showing
9 changed files
with
225 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<!DOCTYPE html> | ||
<!-- | ||
Copyright 2023 The Cobalt Authors. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
|
||
<html> | ||
|
||
<head> | ||
<title>Cobalt Telemetry Test</title> | ||
<script src='black_box_js_test_utils.js'></script> | ||
</head> | ||
|
||
<body> | ||
<script> | ||
const metrics = window.h5vcc.metrics; | ||
const EVENT_INTERVAL_SECS = 5; | ||
let lastMetricType = ''; | ||
let lastPayload = ''; | ||
let payloadCount = 0; | ||
|
||
function metricEventHandler(metricType, payload) { | ||
lastMetricType = metricType; | ||
lastPayload = payload; | ||
payloadCount++; | ||
} | ||
|
||
function initTelemetry() { | ||
metrics.enable(); | ||
metrics.setMetricEventInterval(EVENT_INTERVAL_SECS); | ||
metrics.onMetricEvent(metricEventHandler); | ||
} | ||
|
||
initTelemetry(); | ||
|
||
setupFinished(); | ||
|
||
setTimeout(() => { | ||
assertTrue(metrics.isEnabled(), 'metrics should be enabled'); | ||
assertEqual('COBALT_UMA', lastMetricType, 'metricType should be uma'); | ||
assertTrue(lastPayload.length > 0, 'payload should be non-empty'); | ||
assertEqual(1, payloadCount, 'only one payload sent'); | ||
}, 4000); | ||
|
||
setTimeout(() => { | ||
assertEqual('COBALT_UMA', lastMetricType, 'metricType should be uma'); | ||
assertTrue(lastPayload.length > 0, 'payload should be non-empty'); | ||
assertEqual(2, payloadCount, 'two payloads sent'); | ||
|
||
metrics.disable(); | ||
|
||
setTimeout(() => { | ||
assertFalse(metrics.isEnabled(), 'should disable metrics'); | ||
onEndTest(); | ||
}, 1000); | ||
}, 11000); | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright 2023 The Cobalt Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Tests Cobalt Telemetry functionality.""" | ||
|
||
from cobalt.black_box_tests import black_box_tests | ||
from cobalt.black_box_tests.threaded_web_server import ThreadedWebServer | ||
|
||
|
||
class TelemetryTest(black_box_tests.BlackBoxTestCase): | ||
"""Test Cobalt Telemetry functionality.""" | ||
|
||
def test_telemetry(self): | ||
|
||
with ThreadedWebServer(binding_address=self.GetBindingAddress()) as server: | ||
url = server.GetURL(file_name='testdata/telemetry_test.html') | ||
|
||
# target_params to pass args to cobalt | ||
with self.CreateCobaltRunner( | ||
url=url, | ||
poll_until_wait_seconds=70, | ||
target_params=['--initial-metrics-upload-interval=0']) as runner: | ||
runner.WaitForJSTestsSetup() | ||
self.assertTrue(runner.JSTestsSucceeded()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters