Playback telemetry
This commit is contained in:
1 parent
6e964fa2e5
commit
332e1e7ef6
11 files changed
+1526
-195
No files matched your search
@@ -0,0 +1,452 @@
|
||||
import "pkg:/components/VideoPlayerDev/PlaybackTelemetry.bs"
|
||||
import "pkg:/components/VideoPlayerDev/TransportController.bs"
|
||||
import "pkg:/components/VideoPlayerDev/VideoNode.bs"
|
||||
import "pkg:/source/utils/Locale.bs"
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
|
||||
namespace Tests
|
||||
|
||||
@suite
|
||||
class PlaybackTelemetryTests extends Rooibos.BaseTestSuite
|
||||
|
||||
protected override function beforeEach()
|
||||
' the logger plugin reads m.global.logger; LogTelemetryEvent writes m.global.telemetry.LogEvent.
|
||||
if m.global.logger = invalid
|
||||
m.global.addField("logger", "node", false)
|
||||
m.global.logger = CreateObject("roSGNode", "Logger")
|
||||
end if
|
||||
if m.global.telemetry = invalid
|
||||
m.global.addField("telemetry", "node", false)
|
||||
telemetry = CreateObject("roSGNode", "Node")
|
||||
telemetry.addField("LogEvent", "assocarray", false)
|
||||
m.global.telemetry = telemetry
|
||||
end if
|
||||
m.playerClock = {
|
||||
ms: 0
|
||||
TotalMilliseconds: function() as integer
|
||||
return m.ms
|
||||
end function
|
||||
}
|
||||
m.fakeTransport = {
|
||||
transportMode: TransportController.Mode.Idle
|
||||
isLive: false
|
||||
cursorMs: 0
|
||||
edgeMs: 0
|
||||
SafetyFloorMs: function() as integer
|
||||
return -1
|
||||
end function
|
||||
}
|
||||
m.fakeTop = {
|
||||
content: { videoId: "vid1", backend: "playlet", playletStreamSource: "adaptiveFormats", playletStreamUrlIndex: 0 }
|
||||
state: VideoState.Playing
|
||||
position: 0.0
|
||||
duration: 0.0
|
||||
errorMsg: "There was an error in the HTTP response."
|
||||
errorCode: -1
|
||||
}
|
||||
m.recorder = new PlaybackTelemetry.Recorder({ playerTimer: m.playerClock, transport: m.fakeTransport, top: m.fakeTop })
|
||||
end function
|
||||
|
||||
function At(ms as integer) as void
|
||||
m.playerClock.ms = ms
|
||||
end function
|
||||
|
||||
function State(state as string) as void
|
||||
m.recorder.OnState(state)
|
||||
end function
|
||||
|
||||
function Status(isUnderrun as boolean) as void
|
||||
m.recorder.OnBufferingStatus({ actualStart: 0, isUnderrun: isUnderrun, percentage: 0, prebufferDone: false })
|
||||
end function
|
||||
|
||||
function StartInfo(startType as string) as void
|
||||
m.recorder.OnPlayStartInfo({ start_type: startType, total_dur: 0.5, prebuf_dur: 0.25, drm_load_dur: 0 })
|
||||
end function
|
||||
|
||||
function ReportError() as void
|
||||
m.recorder.ReportVideoError({ title: "Error playing video vid1", body: "errorMsg: http" }, invalid, "http://stream", 0, false)
|
||||
end function
|
||||
|
||||
function SendAt(ms as integer) as object
|
||||
m.At(ms)
|
||||
m.recorder.SendSummary()
|
||||
event = m.global.telemetry.LogEvent
|
||||
m.assertEqual(event.fingerprint, ["playback summary"])
|
||||
return StringUtils.ParseJsonSafe(event.message)
|
||||
end function
|
||||
|
||||
function SortedKeys(aa as object) as object
|
||||
keys = aa.Keys()
|
||||
keys.Sort()
|
||||
return keys
|
||||
end function
|
||||
|
||||
@describe("playback summary")
|
||||
|
||||
@it("a clean play sends only what is not a default")
|
||||
function _()
|
||||
m.At(1000)
|
||||
m.recorder.OnMetadataDone()
|
||||
m.At(1500)
|
||||
m.State(VideoState.Buffering)
|
||||
m.Status(false)
|
||||
m.At(2000)
|
||||
m.State(VideoState.Playing)
|
||||
m.StartInfo("init")
|
||||
summary = m.SendAt(62000)
|
||||
m.assertEqual(m.SortedKeys(summary), ["backend", "first_playing_at_ms", "lifetime_ms", "metadata_done_at_ms", "outcome", "play_start_count", "play_start_infos", "playing_ms", "stream_source"])
|
||||
m.assertEqual(summary.backend, "playlet")
|
||||
m.assertEqual(summary.stream_source, "adaptiveFormats")
|
||||
m.assertEqual(summary.outcome, "closed")
|
||||
m.assertEqual(summary.metadata_done_at_ms, 1000)
|
||||
m.assertEqual(summary.first_playing_at_ms, 2000)
|
||||
m.assertEqual(summary.play_start_count, 1)
|
||||
m.assertEqual(m.SortedKeys(summary.play_start_infos[0]), ["prebuf_dur", "start_type", "total_dur"])
|
||||
m.assertEqual(summary.play_start_infos[0].start_type, "init")
|
||||
m.assertEqual(summary.lifetime_ms, 62000)
|
||||
m.assertEqual(summary.playing_ms, 60000)
|
||||
end function
|
||||
|
||||
@it("count and total cover every underrun; samples stop at 10")
|
||||
function _()
|
||||
m.fakeTransport.isLive = true
|
||||
m.At(1000)
|
||||
m.State(VideoState.Playing)
|
||||
t = 1000
|
||||
for i = 1 to 12
|
||||
t += 10000
|
||||
m.At(t)
|
||||
m.State(VideoState.Buffering)
|
||||
m.Status(true)
|
||||
t += i * 100
|
||||
m.At(t)
|
||||
m.State(VideoState.Playing)
|
||||
end for
|
||||
summary = m.SendAt(t + 1000)
|
||||
m.assertEqual(summary.underrun_count, 12)
|
||||
m.assertEqual(summary.underrun_ms, 7800)
|
||||
m.assertEqual(summary.underrun_samples.Count(), 10)
|
||||
m.assertEqual(summary.underrun_samples[0], { at_ms: 11000, ms: 100 })
|
||||
m.assertEqual(summary.underrun_samples[9].ms, 1000)
|
||||
m.assertTrue(summary.live)
|
||||
m.assertFalse(summary.DoesExist("ended_in_underrun"))
|
||||
m.assertEqual(summary.video_id, "vid1")
|
||||
end function
|
||||
|
||||
@it("a buffering whose first bufferingStatus is no underrun is not counted")
|
||||
function _()
|
||||
m.At(1000)
|
||||
m.State(VideoState.Playing)
|
||||
m.At(5000)
|
||||
m.State(VideoState.Buffering)
|
||||
m.Status(false)
|
||||
m.Status(false)
|
||||
m.At(5500)
|
||||
m.State(VideoState.Playing)
|
||||
summary = m.SendAt(6000)
|
||||
m.assertFalse(summary.DoesExist("underrun_count"))
|
||||
m.assertFalse(summary.DoesExist("bufferings_without_status_count"))
|
||||
m.assertEqual(summary.playing_ms, 4500)
|
||||
end function
|
||||
|
||||
@it("an underrun before the first playing counts")
|
||||
function _()
|
||||
m.At(100)
|
||||
m.State(VideoState.Buffering)
|
||||
m.Status(true)
|
||||
m.At(2100)
|
||||
m.State(VideoState.Playing)
|
||||
summary = m.SendAt(3000)
|
||||
m.assertEqual(summary.underrun_count, 1)
|
||||
m.assertEqual(summary.underrun_samples[0], { at_ms: 100, ms: 2000 })
|
||||
end function
|
||||
|
||||
@it("a buffering with no valid bufferingStatus is counted as one, with the video id")
|
||||
function _()
|
||||
m.At(1000)
|
||||
m.State(VideoState.Playing)
|
||||
m.At(5000)
|
||||
m.State(VideoState.Buffering)
|
||||
m.recorder.OnBufferingStatus(invalid)
|
||||
m.At(5150)
|
||||
m.State(VideoState.Playing)
|
||||
summary = m.SendAt(6000)
|
||||
m.assertEqual(summary.bufferings_without_status_count, 1)
|
||||
m.assertFalse(summary.DoesExist("underrun_count"))
|
||||
m.assertEqual(summary.playing_ms, 4850)
|
||||
m.assertEqual(summary.video_id, "vid1")
|
||||
end function
|
||||
|
||||
@it("a buffering cut short before any status is not counted: a pause, an error, the close")
|
||||
function _()
|
||||
m.At(1000)
|
||||
m.State(VideoState.Playing)
|
||||
m.State(VideoState.Buffering)
|
||||
m.State(VideoState.Paused)
|
||||
m.State(VideoState.Buffering)
|
||||
m.State(VideoState.Error)
|
||||
m.State(VideoState.Buffering)
|
||||
summary = m.SendAt(2000)
|
||||
m.assertFalse(summary.DoesExist("bufferings_without_status_count"))
|
||||
end function
|
||||
|
||||
@it("an update with no boolean isUnderrun is no status")
|
||||
function _()
|
||||
m.At(1000)
|
||||
m.State(VideoState.Playing)
|
||||
m.State(VideoState.Buffering)
|
||||
m.recorder.OnBufferingStatus({ percentage: 33, prebufferDone: true })
|
||||
m.recorder.OnBufferingStatus({ isUnderrun: "true", percentage: 99 })
|
||||
m.At(2000)
|
||||
m.State(VideoState.Playing)
|
||||
summary = m.SendAt(3000)
|
||||
m.assertEqual(summary.bufferings_without_status_count, 1)
|
||||
m.assertFalse(summary.DoesExist("underrun_count"))
|
||||
end function
|
||||
|
||||
@it("the first bufferingStatus classifies; each later isUnderrun change is counted")
|
||||
function _()
|
||||
m.At(1000)
|
||||
m.State(VideoState.Playing)
|
||||
m.At(5000)
|
||||
m.State(VideoState.Buffering)
|
||||
m.Status(false)
|
||||
m.Status(true)
|
||||
m.Status(true)
|
||||
m.Status(false)
|
||||
m.At(6000)
|
||||
m.State(VideoState.Playing)
|
||||
summary = m.SendAt(7000)
|
||||
m.assertEqual(summary.is_underrun_change_count, 2)
|
||||
m.assertFalse(summary.DoesExist("underrun_count"))
|
||||
m.assertEqual(summary.video_id, "vid1")
|
||||
end function
|
||||
|
||||
@it("a bufferingStatus outside a buffering is ignored")
|
||||
function _()
|
||||
m.At(1000)
|
||||
m.State(VideoState.Playing)
|
||||
m.Status(true)
|
||||
m.At(2000)
|
||||
m.State(VideoState.Paused)
|
||||
m.Status(true)
|
||||
summary = m.SendAt(3000)
|
||||
m.assertFalse(summary.DoesExist("underrun_count"))
|
||||
m.assertFalse(summary.DoesExist("is_underrun_change_count"))
|
||||
end function
|
||||
|
||||
@it("an underrun ends at a pause")
|
||||
function _()
|
||||
m.At(1000)
|
||||
m.State(VideoState.Playing)
|
||||
m.At(5000)
|
||||
m.State(VideoState.Buffering)
|
||||
m.Status(true)
|
||||
m.At(6000)
|
||||
m.State(VideoState.Paused)
|
||||
m.At(9000)
|
||||
m.State(VideoState.Buffering)
|
||||
m.Status(false)
|
||||
m.At(9100)
|
||||
m.State(VideoState.Playing)
|
||||
summary = m.SendAt(10000)
|
||||
m.assertEqual(summary.underrun_count, 1)
|
||||
m.assertEqual(summary.underrun_samples[0], { at_ms: 5000, ms: 1000 })
|
||||
end function
|
||||
|
||||
@it("an underrun still running at the send counts up to it, and ended the playback")
|
||||
function _()
|
||||
m.At(1000)
|
||||
m.State(VideoState.Playing)
|
||||
m.At(5000)
|
||||
m.State(VideoState.Buffering)
|
||||
m.Status(true)
|
||||
summary = m.SendAt(8000)
|
||||
m.assertEqual(summary.underrun_count, 1)
|
||||
m.assertEqual(summary.underrun_samples[0], { at_ms: 5000, ms: 3000 })
|
||||
m.assertTrue(summary.ended_in_underrun)
|
||||
m.assertEqual(summary.playing_ms, 4000)
|
||||
end function
|
||||
|
||||
@it("every playStartInfo is counted; the first 10 are kept as written")
|
||||
function _()
|
||||
m.recorder.OnPlayStartInfo(invalid)
|
||||
m.StartInfo("init")
|
||||
for i = 1 to 11
|
||||
m.StartInfo("cseek")
|
||||
end for
|
||||
summary = m.SendAt(1000)
|
||||
m.assertEqual(summary.play_start_count, 12)
|
||||
m.assertEqual(summary.play_start_infos.Count(), 10)
|
||||
m.assertEqual(summary.play_start_infos[0].start_type, "init")
|
||||
m.assertEqual(summary.play_start_infos[1].start_type, "cseek")
|
||||
end function
|
||||
|
||||
@it("a video that never played: -1 for what never happened, with its video id")
|
||||
function _()
|
||||
m.At(100)
|
||||
m.State(VideoState.Buffering)
|
||||
summary = m.SendAt(9000)
|
||||
m.assertEqual(summary.metadata_done_at_ms, -1)
|
||||
m.assertEqual(summary.first_playing_at_ms, -1)
|
||||
m.assertFalse(summary.DoesExist("bufferings_without_status_count"), "a buffering open at the close never reached playing")
|
||||
m.assertFalse(summary.DoesExist("play_start_infos"))
|
||||
m.assertFalse(summary.DoesExist("playing_ms"))
|
||||
m.assertEqual(summary.video_id, "vid1")
|
||||
end function
|
||||
|
||||
@it("DRM content from the DASH manifest url, after a retry")
|
||||
function _()
|
||||
m.fakeTop.content = { videoId: "vid1", backend: "playlet", playletStreamSource: "dashUrl", playletStreamUrlIndex: 1, drmParams: { keySystem: "Widevine" } }
|
||||
summary = m.SendAt(1000)
|
||||
m.assertTrue(summary.drm)
|
||||
m.assertEqual(summary.stream_source, "dashUrl")
|
||||
m.assertEqual(summary.stream_url_index, 1)
|
||||
end function
|
||||
|
||||
@it("content that never loaded sends no stream fields")
|
||||
function _()
|
||||
m.fakeTop.content = { videoId: "vid1", backend: "playlet" }
|
||||
summary = m.SendAt(1000)
|
||||
m.assertFalse(summary.DoesExist("stream_source"))
|
||||
m.assertFalse(summary.DoesExist("drm"))
|
||||
m.assertFalse(summary.DoesExist("stream_url_index"))
|
||||
end function
|
||||
|
||||
@it("an error dialog ends the playback in error")
|
||||
function _()
|
||||
m.At(1000)
|
||||
m.State(VideoState.Playing)
|
||||
m.At(2000)
|
||||
m.ReportError()
|
||||
m.State(VideoState.Error)
|
||||
m.recorder.OnErrorDialog()
|
||||
summary = m.SendAt(3000)
|
||||
m.assertEqual(summary.outcome, "error")
|
||||
m.assertEqual(summary.error_count, 1)
|
||||
m.assertEqual(summary.playing_ms, 1000)
|
||||
m.assertEqual(summary.video_id, "vid1")
|
||||
end function
|
||||
|
||||
@it("playing under the error dialog: recovered, so the error did not end it")
|
||||
function _()
|
||||
m.ReportError()
|
||||
m.State(VideoState.Error)
|
||||
m.recorder.OnErrorDialog()
|
||||
m.At(2000)
|
||||
m.State(VideoState.Playing)
|
||||
summary = m.SendAt(4000)
|
||||
m.assertEqual(summary.outcome, "closed")
|
||||
m.assertEqual(summary.error_count, 1)
|
||||
m.assertEqual(summary.video_id, "vid1")
|
||||
end function
|
||||
|
||||
@it("a finished video ends in finished")
|
||||
function _()
|
||||
m.At(1000)
|
||||
m.State(VideoState.Playing)
|
||||
m.At(9000)
|
||||
m.State(VideoState.Finished)
|
||||
m.recorder.OnFinished()
|
||||
summary = m.SendAt(9000)
|
||||
m.assertEqual(summary.outcome, "finished")
|
||||
m.assertEqual(summary.playing_ms, 8000)
|
||||
m.assertFalse(summary.DoesExist("video_id"), "a clean finish carries no video id")
|
||||
end function
|
||||
|
||||
@it("heals: all counted, the first 3 sampled, no event of their own")
|
||||
function _()
|
||||
m.fakeTransport.transportMode = TransportController.Mode.Scrub
|
||||
m.fakeTransport.cursorMs = 48000
|
||||
m.fakeTop.position = 51.2
|
||||
m.State(VideoState.Playing)
|
||||
m.global.telemetry.LogEvent = {}
|
||||
for i = 1 to 5
|
||||
m.At(i * 1000)
|
||||
m.recorder.RecordHeal("OnPosition")
|
||||
end for
|
||||
m.assertInvalid(m.global.telemetry.LogEvent.message, "a heal sends nothing until the summary")
|
||||
summary = m.SendAt(9000)
|
||||
m.assertEqual(summary.heal_count, 5)
|
||||
m.assertEqual(summary.heal_samples.Count(), 3)
|
||||
m.assertEqual(summary.heal_samples[0], { at_ms: 1000, source: "OnPosition", mode: TransportController.Mode.Scrub, position_ms: 51200, cursor_ms: 48000, floor_ms: -1 })
|
||||
m.assertEqual(summary.video_id, "vid1")
|
||||
end function
|
||||
|
||||
@it("tail resolves: all counted, the first 3 sampled, no event of their own, no video id")
|
||||
function _()
|
||||
m.fakeTransport.isLive = true
|
||||
m.fakeTransport.cursorMs = 6134000
|
||||
m.fakeTransport.edgeMs = 6640000
|
||||
m.fakeTransport.SafetyFloorMs = function() as integer
|
||||
return 6134000
|
||||
end function
|
||||
m.fakeTop.position = 6137.0
|
||||
m.State(VideoState.Playing)
|
||||
m.global.telemetry.LogEvent = {}
|
||||
for i = 1 to 4
|
||||
m.At(i * 1000)
|
||||
m.recorder.RecordTailResolve("OnVideoState")
|
||||
end for
|
||||
m.assertInvalid(m.global.telemetry.LogEvent.message, "a tail resolve sends nothing until the summary")
|
||||
summary = m.SendAt(9000)
|
||||
m.assertEqual(summary.tail_resolve_count, 4)
|
||||
m.assertEqual(summary.tail_resolve_samples.Count(), 3)
|
||||
m.assertEqual(summary.tail_resolve_samples[0], { at_ms: 1000, source: "OnVideoState", position_ms: 6137000, cursor_ms: 6134000, floor_ms: 6134000, edge_ms: 6640000 })
|
||||
m.assertFalse(summary.DoesExist("video_id"))
|
||||
end function
|
||||
|
||||
@it("no content: an unknown backend, no content fields")
|
||||
function _()
|
||||
m.fakeTop.content = invalid
|
||||
summary = m.SendAt(1000)
|
||||
m.assertEqual(summary.backend, "unknown")
|
||||
m.assertFalse(summary.DoesExist("video_id"))
|
||||
m.assertFalse(summary.DoesExist("stream_source"))
|
||||
end function
|
||||
|
||||
@it("a video error report: its level, fingerprint and the summary's error count")
|
||||
function _()
|
||||
m.fakeTop.content = { videoId: "vid1", backend: "playlet", playletStreamUrls: ["http://a", "http://b"] }
|
||||
errorInfo = { source: "buffer:reader", ignored: false, category: "http" }
|
||||
m.recorder.ReportVideoError({ title: "Error playing video vid1", body: "errorMsg: http" }, errorInfo, "http://a", 0, false)
|
||||
m.assertEqual(m.global.telemetry.LogEvent.level, "warning", "retried: not shown to the viewer")
|
||||
m.recorder.ReportVideoError({ title: "Error playing video vid1", body: "errorMsg: http" }, errorInfo, "http://b", 1, true)
|
||||
sent = m.global.telemetry.LogEvent
|
||||
m.assertEqual(sent.level, "error")
|
||||
m.assertTrue(sent.message.InStr("Url: http://b") > 0 and sent.message.InStr("Url index: 1") > 0, "got: " + sent.message)
|
||||
m.assertTrue(sent.message.InStr(`Urls: ["http://a","http://b"]`) > 0, "got: " + sent.message)
|
||||
m.assertEqual(sent.fingerprint, [Locale.VideoPlayer.ErrorPlayingVideo, "There was an error in the HTTP response.", -1, "buffer:reader", false, "http", invalid, invalid, true, false, "none", false, "playlet", false])
|
||||
m.assertTrue(sent.message.InStr("backend: playlet") > 0, "got: " + sent.message)
|
||||
m.assertEqual(m.SendAt(1000).error_count, 2)
|
||||
end function
|
||||
|
||||
@describe("OmitDefaults")
|
||||
|
||||
@it("drops false, 0, 0.0, empty strings and arrays and invalid at every depth; keeps -1 and the rest")
|
||||
function _()
|
||||
value = {
|
||||
f: false
|
||||
zero: 0
|
||||
zeroFloat: 0.0
|
||||
empty: ""
|
||||
none: []
|
||||
missing: invalid
|
||||
never: -1
|
||||
yes: true
|
||||
text: "x"
|
||||
list: [{ zero: 0, one: 1 }]
|
||||
nested: { zero: 0, inner: { f: false, two: 2.5 } }
|
||||
}
|
||||
m.assertEqual(PlaybackTelemetry.OmitDefaults(value), {
|
||||
never: -1
|
||||
yes: true
|
||||
text: "x"
|
||||
list: [{ one: 1 }]
|
||||
nested: { inner: { two: 2.5 } }
|
||||
})
|
||||
end function
|
||||
|
||||
end class
|
||||
|
||||
end namespace
|
||||
@@ -0,0 +1,412 @@
|
||||
' Completeness suite for the playback summary: every short input sequence (exhaustive) and long random ones
|
||||
' (seeded fuzz, shrunk to a minimal repro) go through the Recorder, and the summary it sends must equal the one
|
||||
' an independent model rebuilds from the same event log, interval by interval.
|
||||
|
||||
import "pkg:/components/VideoPlayerDev/PlaybackTelemetry.bs"
|
||||
import "pkg:/components/VideoPlayerDev/TransportController.bs"
|
||||
import "pkg:/components/VideoPlayerDev/VideoNode.bs"
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
namespace Tests
|
||||
|
||||
@suite
|
||||
class PlaybackTelemetryCompletenessTests extends Rooibos.BaseTestSuite
|
||||
|
||||
protected override function beforeEach()
|
||||
if m.global.logger = invalid
|
||||
m.global.addField("logger", "node", false)
|
||||
m.global.logger = CreateObject("roSGNode", "Logger")
|
||||
end if
|
||||
if m.global.telemetry = invalid
|
||||
m.global.addField("telemetry", "node", false)
|
||||
telemetry = CreateObject("roSGNode", "Node")
|
||||
telemetry.addField("LogEvent", "assocarray", false)
|
||||
m.global.telemetry = telemetry
|
||||
end if
|
||||
end function
|
||||
|
||||
' ---------- inputs ----------
|
||||
|
||||
' One token = one input to the Recorder. The span tokens (0-8) drive the state machine; the rest are every
|
||||
' other input the coordinator forwards.
|
||||
function Tokens() as object
|
||||
return [
|
||||
{ kind: "wait", ms: 1000 } ' 0
|
||||
{ kind: "state", state: VideoState.Playing } ' 1
|
||||
{ kind: "state", state: VideoState.Buffering } ' 2
|
||||
{ kind: "state", state: VideoState.Paused } ' 3
|
||||
{ kind: "state", state: VideoState.Error } ' 4
|
||||
{ kind: "status", status: { isUnderrun: true, percentage: 33 } } ' 5
|
||||
{ kind: "status", status: { isUnderrun: false, percentage: 33 } } ' 6
|
||||
{ kind: "status", status: invalid } ' 7
|
||||
{ kind: "status", status: { percentage: 33 } } ' 8: no isUnderrun
|
||||
{ kind: "wait", ms: 37 } ' 9
|
||||
{ kind: "state", state: VideoState.Finished } ' 10
|
||||
{ kind: "state", state: VideoState.Stopped } ' 11
|
||||
{ kind: "start", info: { start_type: "init", total_dur: 1, prebuf_dur: 0 } } ' 12
|
||||
{ kind: "start", info: { start_type: "cseek", total_dur: 2 } } ' 13
|
||||
{ kind: "start", info: invalid } ' 14
|
||||
{ kind: "heal" } ' 15
|
||||
{ kind: "tail" } ' 16
|
||||
{ kind: "videoError" } ' 17
|
||||
{ kind: "dialog" } ' 18
|
||||
{ kind: "finished" } ' 19
|
||||
{ kind: "metadata" } ' 20
|
||||
{ kind: "status", status: { isUnderrun: "true" } } ' 21: a non-boolean isUnderrun
|
||||
]
|
||||
end function
|
||||
|
||||
function NewTrial() as object
|
||||
trial = {
|
||||
clock: {
|
||||
ms: 0
|
||||
TotalMilliseconds: function() as integer
|
||||
return m.ms
|
||||
end function
|
||||
}
|
||||
transport: {
|
||||
transportMode: TransportController.Mode.Scrub
|
||||
isLive: false
|
||||
cursorMs: 4000
|
||||
edgeMs: 0
|
||||
SafetyFloorMs: function() as integer
|
||||
return -1
|
||||
end function
|
||||
}
|
||||
top: {
|
||||
content: { videoId: "vid1", backend: "playlet", playletStreamSource: "adaptiveFormats", playletStreamUrlIndex: 0 }
|
||||
state: VideoState.Playing
|
||||
position: 3.0
|
||||
duration: 0.0
|
||||
errorMsg: "boom"
|
||||
errorCode: -1
|
||||
}
|
||||
log: []
|
||||
}
|
||||
trial.recorder = new PlaybackTelemetry.Recorder({ playerTimer: trial.clock, transport: trial.transport, top: trial.top })
|
||||
return trial
|
||||
end function
|
||||
|
||||
function Apply(trial as object, token as object) as void
|
||||
trial.log.Push({ at: trial.clock.ms, token: token })
|
||||
r = trial.recorder
|
||||
kind = token.kind
|
||||
if kind = "wait"
|
||||
trial.clock.ms += token.ms
|
||||
else if kind = "state"
|
||||
r.OnState(token.state)
|
||||
else if kind = "status"
|
||||
r.OnBufferingStatus(token.status)
|
||||
else if kind = "start"
|
||||
r.OnPlayStartInfo(token.info)
|
||||
else if kind = "heal"
|
||||
r.RecordHeal("OnPosition")
|
||||
else if kind = "tail"
|
||||
r.RecordTailResolve("OnVideoState")
|
||||
else if kind = "videoError"
|
||||
r.ReportVideoError({ title: "t", body: "b" }, invalid, "http://a", 0, false)
|
||||
else if kind = "dialog"
|
||||
r.OnErrorDialog()
|
||||
else if kind = "finished"
|
||||
r.OnFinished()
|
||||
else if kind = "metadata"
|
||||
r.OnMetadataDone()
|
||||
end if
|
||||
end function
|
||||
|
||||
function Sent(trial as object) as object
|
||||
trial.recorder.SendSummary()
|
||||
return StringUtils.ParseJsonSafe(m.global.telemetry.LogEvent.message)
|
||||
end function
|
||||
|
||||
' ---------- the model: the summary rebuilt from the event log, one state interval at a time ----------
|
||||
|
||||
function Expected(trial as object) as object
|
||||
log = trial.log
|
||||
lifetimeMs = trial.clock.ms
|
||||
' intervals between state edges; the last one runs to the send (next state "").
|
||||
edges = []
|
||||
for i = 0 to log.Count() - 1
|
||||
if log[i].token.kind = "state"
|
||||
edges.Push(i)
|
||||
end if
|
||||
end for
|
||||
playingMs = 0
|
||||
underrunCount = 0
|
||||
underrunMs = 0
|
||||
samples = []
|
||||
withoutStatus = 0
|
||||
changes = 0
|
||||
endedInUnderrun = false
|
||||
for e = 0 to edges.Count() - 1
|
||||
startIndex = edges[e]
|
||||
state = log[startIndex].token.state
|
||||
startMs = log[startIndex].at
|
||||
if e + 1 < edges.Count()
|
||||
endIndex = edges[e + 1]
|
||||
endMs = log[endIndex].at
|
||||
nextState = log[endIndex].token.state
|
||||
else
|
||||
endIndex = log.Count()
|
||||
endMs = lifetimeMs
|
||||
nextState = ""
|
||||
end if
|
||||
if state = VideoState.Playing
|
||||
playingMs += endMs - startMs
|
||||
else if state = VideoState.Buffering
|
||||
values = []
|
||||
for i = startIndex + 1 to endIndex - 1
|
||||
token = log[i].token
|
||||
if token.kind = "status" and token.status <> invalid and IsBool(token.status.isUnderrun)
|
||||
values.Push(token.status.isUnderrun)
|
||||
end if
|
||||
end for
|
||||
if values.Count() = 0
|
||||
if nextState = VideoState.Playing
|
||||
withoutStatus += 1
|
||||
end if
|
||||
else
|
||||
for i = 1 to values.Count() - 1
|
||||
if values[i] <> values[i - 1]
|
||||
changes += 1
|
||||
end if
|
||||
end for
|
||||
if values[0]
|
||||
underrunCount += 1
|
||||
underrunMs += endMs - startMs
|
||||
if samples.Count() < 10
|
||||
samples.Push({ "at_ms": startMs, "ms": endMs - startMs })
|
||||
end if
|
||||
endedInUnderrun = nextState = ""
|
||||
end if
|
||||
end if
|
||||
end if
|
||||
end for
|
||||
|
||||
outcome = "closed"
|
||||
metadataDoneAtMs = -1
|
||||
firstPlayingAtMs = -1
|
||||
starts = []
|
||||
startCount = 0
|
||||
errorCount = 0
|
||||
healCount = 0
|
||||
heals = []
|
||||
tailCount = 0
|
||||
tails = []
|
||||
for each entry in log
|
||||
token = entry.token
|
||||
kind = token.kind
|
||||
if kind = "state" and token.state = VideoState.Playing
|
||||
if firstPlayingAtMs < 0
|
||||
firstPlayingAtMs = entry.at
|
||||
end if
|
||||
if outcome = "error"
|
||||
outcome = "closed"
|
||||
end if
|
||||
else if kind = "dialog"
|
||||
outcome = "error"
|
||||
else if kind = "finished"
|
||||
outcome = "finished"
|
||||
else if kind = "metadata"
|
||||
metadataDoneAtMs = entry.at
|
||||
else if kind = "start" and token.info <> invalid
|
||||
startCount += 1
|
||||
if starts.Count() < 10
|
||||
starts.Push(token.info)
|
||||
end if
|
||||
else if kind = "videoError"
|
||||
errorCount += 1
|
||||
else if kind = "heal"
|
||||
healCount += 1
|
||||
if heals.Count() < 3
|
||||
heals.Push({ "at_ms": entry.at, "source": "OnPosition", "mode": trial.transport.transportMode, "position_ms": 3000, "cursor_ms": 4000, "edge_ms": 0, "floor_ms": -1 })
|
||||
end if
|
||||
else if kind = "tail"
|
||||
tailCount += 1
|
||||
if tails.Count() < 3
|
||||
tails.Push({ "at_ms": entry.at, "source": "OnVideoState", "position_ms": 3000, "cursor_ms": 4000, "floor_ms": -1, "edge_ms": 0 })
|
||||
end if
|
||||
end if
|
||||
end for
|
||||
|
||||
expected = {
|
||||
"live": false
|
||||
"backend": "playlet"
|
||||
"stream_source": "adaptiveFormats"
|
||||
"drm": false
|
||||
"stream_url_index": 0
|
||||
"outcome": outcome
|
||||
"metadata_done_at_ms": metadataDoneAtMs
|
||||
"first_playing_at_ms": firstPlayingAtMs
|
||||
"play_start_infos": starts
|
||||
"play_start_count": startCount
|
||||
"lifetime_ms": lifetimeMs
|
||||
"playing_ms": playingMs
|
||||
"underrun_count": underrunCount
|
||||
"underrun_ms": underrunMs
|
||||
"underrun_samples": samples
|
||||
"ended_in_underrun": endedInUnderrun
|
||||
"bufferings_without_status_count": withoutStatus
|
||||
"is_underrun_change_count": changes
|
||||
"error_count": errorCount
|
||||
"heal_count": healCount
|
||||
"heal_samples": heals
|
||||
"tail_resolve_count": tailCount
|
||||
"tail_resolve_samples": tails
|
||||
}
|
||||
if firstPlayingAtMs < 0 or underrunCount > 0 or withoutStatus > 0 or changes > 0 or errorCount > 0 or healCount > 0 or outcome = "error"
|
||||
expected["video_id"] = "vid1"
|
||||
end if
|
||||
return m.WithoutDefaults(expected)
|
||||
end function
|
||||
|
||||
' the wire rule, written independently of PlaybackTelemetry.OmitDefaults.
|
||||
function WithoutDefaults(value as dynamic) as dynamic
|
||||
if IsArray(value)
|
||||
out = []
|
||||
for each item in value
|
||||
out.Push(m.WithoutDefaults(item))
|
||||
end for
|
||||
return out
|
||||
end if
|
||||
if not IsAssociativeArray(value)
|
||||
return value
|
||||
end if
|
||||
out = {}
|
||||
for each key in value
|
||||
item = value[key]
|
||||
keep = true
|
||||
if item = invalid
|
||||
keep = false
|
||||
else if IsBool(item)
|
||||
keep = item
|
||||
else if IsInt(item) or IsFloat(item)
|
||||
keep = item <> 0
|
||||
else if IsString(item)
|
||||
keep = item <> ""
|
||||
else if IsArray(item)
|
||||
keep = item.Count() > 0
|
||||
end if
|
||||
if keep
|
||||
out[key] = m.WithoutDefaults(item)
|
||||
end if
|
||||
end for
|
||||
return out
|
||||
end function
|
||||
|
||||
' replay a token sequence and compare; "" when the summary matches the model, else both summaries.
|
||||
function Mismatch(sequence as object) as string
|
||||
trial = m.NewTrial()
|
||||
tokens = m.Tokens()
|
||||
for each index in sequence
|
||||
m.Apply(trial, tokens[index])
|
||||
end for
|
||||
actual = FormatJson(m.Sent(trial))
|
||||
expected = FormatJson(m.Expected(trial))
|
||||
if actual = expected
|
||||
return ""
|
||||
end if
|
||||
return "sent " + actual + " | model " + expected
|
||||
end function
|
||||
|
||||
@describe("playback summary completeness")
|
||||
|
||||
' "" when every sequence of `length` span tokens matches the model, else the first that does not.
|
||||
function ExhaustiveFailure(length as integer) as string
|
||||
spanTokens = 9
|
||||
total = 1
|
||||
for i = 1 to length
|
||||
total *= spanTokens
|
||||
end for
|
||||
for n = 0 to total - 1
|
||||
sequence = []
|
||||
rest = n
|
||||
for i = 1 to length
|
||||
sequence.Push(rest mod spanTokens)
|
||||
rest = rest \ spanTokens
|
||||
end for
|
||||
failure = m.Mismatch(sequence)
|
||||
if failure <> ""
|
||||
return "tokens " + FormatJson(sequence) + ": " + failure
|
||||
end if
|
||||
end for
|
||||
return ""
|
||||
end function
|
||||
|
||||
@it("every sequence of 4 span inputs sends the summary the model rebuilds")
|
||||
function _()
|
||||
m.assertEqual(m.ExhaustiveFailure(4), "")
|
||||
end function
|
||||
|
||||
' ---------- seeded fuzz with shrink ----------
|
||||
|
||||
' a 16-bit LCG: deterministic and reproducible (Rnd is clock-seeded).
|
||||
function Lcg(s as integer) as integer
|
||||
return (s * 25173 + 13849) and 65535
|
||||
end function
|
||||
|
||||
function GenSequence(seed as integer, n as integer, count as integer) as object
|
||||
sequence = []
|
||||
s = seed
|
||||
for i = 0 to n - 1
|
||||
s = m.Lcg(s)
|
||||
sequence.Push(s mod count)
|
||||
end for
|
||||
return sequence
|
||||
end function
|
||||
|
||||
function Shrink(sequence as object) as object
|
||||
for k = 0 to sequence.Count() - 1
|
||||
prefix = []
|
||||
for j = 0 to k
|
||||
prefix.Push(sequence[j])
|
||||
end for
|
||||
if m.Mismatch(prefix) <> ""
|
||||
return prefix
|
||||
end if
|
||||
end for
|
||||
return sequence
|
||||
end function
|
||||
|
||||
function FuzzFailure(seeds as object, length as integer, tokenCount as integer) as string
|
||||
for each seed in seeds
|
||||
sequence = m.GenSequence(seed, length, tokenCount)
|
||||
if m.Mismatch(sequence) <> ""
|
||||
minimal = m.Shrink(sequence)
|
||||
return "seed=" + seed.ToStr() + "; minimal repro (" + minimal.Count().ToStr() + " tokens) " + FormatJson(minimal) + ": " + m.Mismatch(minimal)
|
||||
end if
|
||||
end for
|
||||
return ""
|
||||
end function
|
||||
|
||||
@it("seeded random sequences of every input send the summary the model rebuilds (shrinkable)")
|
||||
function _()
|
||||
m.assertEqual(m.FuzzFailure([1, 2, 7, 42, 1337, 4242, 9001, 31337], 120, m.Tokens().Count()), "")
|
||||
end function
|
||||
|
||||
@it("seeded random sequences of span inputs send the summary the model rebuilds (shrinkable)")
|
||||
function _()
|
||||
seeds = []
|
||||
for seed = 100 to 160
|
||||
seeds.Push(seed)
|
||||
end for
|
||||
m.assertEqual(m.FuzzFailure(seeds, 60, 9), "")
|
||||
end function
|
||||
|
||||
@it("every summary the fuzz sends carries no default value at any depth")
|
||||
function _()
|
||||
for each seed in [3, 5, 11]
|
||||
trial = m.NewTrial()
|
||||
tokens = m.Tokens()
|
||||
for each index in m.GenSequence(seed, 120, tokens.Count())
|
||||
m.Apply(trial, tokens[index])
|
||||
end for
|
||||
sent = m.Sent(trial)
|
||||
m.assertEqual(FormatJson(sent), FormatJson(m.WithoutDefaults(sent)), "seed=" + seed.ToStr())
|
||||
end for
|
||||
end function
|
||||
|
||||
end class
|
||||
|
||||
end namespace
|
||||
Reference in new issue
Block a user