Skip to content

Flaky VideoBlock JS tests #290

Open
Open

Description

@kdmccormick

Several VideoBlock karma tests seem to be flakey.

By my estimate, one of any of these fails around 10% of the time.

1) player state was changed
     Video HTML5Video non-hls encoding on non-Touch devices  events: [play]
     Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. in http://localhost:9876/absolute/home/runner/work/xblocks-core/xblocks-core/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?da99c5b057693d025fad3d7685e1590600ca376d (line 3938)
QueueRunner.prototype.run/attemptAsync/timeoutId<@http://localhost:9876/absolute/home/runner/work/xblocks-core/xblocks-core/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?da99c5b057693d025fad3d7685e1590600ca376d:3938:23
2) callback was called
     Video HTML5Video non-hls encoding on non-Touch devices  events: [play]
     Expected [ 3, 1 ] to contain -1.
../tests/js/html5_video_spec.js/</</describeInfo</</</</<@http://localhost:9876/base/public/js/commons.js?70e765de13f56a983143d5c15cc43f401e110fe8:65273:72
Deferred/then/</</<@http://localhost:9876/base/assets/js/src/vendor/jquery.js?26e6b63b81813d8ad942c90d369df2673602b812:3366:33
fire@http://localhost:9876/base/assets/js/src/vendor/jquery.js?26e6b63b81813d8ad942c90d369df2673602b812:3187:31
fireWith@http://localhost:9876/base/assets/js/src/vendor/jquery.js?26e6b63b81813d8ad942c90d369df2673602b812:3317:7     Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. in http://localhost:9876/absolute/home/runner/work/xblocks-core/xblocks-core/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?da99c5b057693d025fad3d7685e1590600ca376d (line 3938)
QueueRunner.prototype.run/attemptAsync/timeoutId<@http://localhost:9876/absolute/home/runner/work/xblocks-core/xblocks-core/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?da99c5b057693d025fad3d7685e1590600ca376d:3938:23
3) callback was called
     Video HTML5Video hls encoding on non-Touch devices  events: [play]
     Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. in http://localhost:9876/absolute/home/runner/work/xblocks-core/xblocks-core/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?da99c5b057693d025fad3d7685e1590600ca376d (line 3938)
QueueRunner.prototype.run/attemptAsync/timeoutId<@http://localhost:9876/absolute/home/runner/work/xblocks-core/xblocks-core/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?da99c5b057693d025fad3d7685e1590600ca376d:3938:23

Activity

  1. added
    flaky-test
    on Aug 13, 2026
  2. changed the title [-]Flaky VideoBlock tests[/-] [+]Flaky VideoBlock JS tests[/+] on Aug 13, 2026
  3. kdmccormick commented on Aug 13, 2026

    @kdmccormick
    MemberAuthor

    @openedx/axim-aximprovements No action needed right now, but I just wanted to share that I've been noticing that there is flakiness in a few of the VideoBlock JS tests. Curious if any of you guys hit this when developing, too. We can consider fixing or removing them in the future if they prove to be disruptive.

  4. kdmccormick commented on Aug 13, 2026

    @kdmccormick
    MemberAuthor

    summary from Claude Opus. Claude is pretty confident about this, but I'm not exactly sure.


    Flaky video JS tests: waitUntil timeouts blame the wrong spec

    Symptom

    Occasional failures in the video-xblock Karma/Jasmine suite
    (src/xblock_video), most often on specs named player state was changed
    under Video HTML5Video … events: [play] | [pause] | …, reported as:

    Failed: Timeout has expired
    

    Characteristics that make it confusing:

    • The failing spec name varies run to run ([play] one time, [pause]
      the next, sometimes an hls vs non-hls variant).
    • It sometimes lands on a synchronous spec that has no waitUntil and
      therefore cannot itself time out.
    • It fails more frequently in CI than on a local machine with a real,
      focused browser.

    Root cause

    The shared helper tests/spec_helpers/jasmine-waituntil.js has two properties
    that combine badly:

    1. It polls with the real, unmocked setTimeout, so its timer keeps
      running across spec boundaries.
    2. On timeout it calls the global fail(), which fails whichever spec is
      currently executing
      .

    So when a waitUntil started in spec A never satisfies its condition, its
    timer keeps ticking after A finishes and, ~jasmine.DEFAULT_TIMEOUT_INTERVAL
    later, calls fail() during some unrelated later spec B. B gets blamed — even
    if B is synchronous. The reported spec name is essentially "whoever was running
    when the leaked timer expired," which is why it wanders.

    The trigger is that many of these specs wait on real, timing-dependent
    HTML5 media events — especially reaching STATUS.PLAYING, which needs the
    browser's real playing event on a <video> actually decoding the fixture.
    Headless CI (no autoplay/user-gesture, no window focus) makes those events fire
    late or never, so the waits time out and the leaked fail() fires. A local run
    with a real focused browser reaches those states more reliably, hence the lower
    local failure rate. Anything that perturbs event-loop/focus timing (e.g. a
    browser modal) shifts the failure rate too.

    Suggested fixes (in preference order)

    1. Harden the helper. Track pending waitUntil timers and clear them in a
      global afterEach so no timer survives its spec. Keep failing the spec on a
      genuinely unmet condition — but attribute it to the spec that owns the wait,
      not a bystander. This is a small change to shared infra and removes the
      cross-spec mislabeling that makes the flake so hard to read.

    2. Make individual specs deterministic. Where a spec asserts a state, have
      its waitUntil poll for that state rather than a looser condition, and/or
      fire synthetic media events instead of relying on real playback. Example
      already applied: the [pause] "player state was changed" spec now waits for
      === STATUS.PAUSED (the asserted state) instead of !== STATUS.PLAYING
      (which BUFFERING also satisfies), closing that particular race.

    Fix (1) addresses the mechanism; fix (2) reduces how often it's triggered.

    Reproducing / debugging

    • --grep does not filter on this toolchain (karma-jasmine 0.3.8 +
      jasmine-core 2.6.4 ignore the adapter's specFilter). Use Jasmine focus
      (fit / fdescribe) to narrow to a spec, and/or comment out spec imports in
      assets/karma.webpack.entry.js to shrink the bundle.
    • Because failures are mislabeled, isolating a single spec can hide the flake
      (the real offender is a different, earlier spec). Run a representative
      subset repeatedly and watch whether the named failing spec changes — that
      variance is itself the tell for cross-spec contamination.
  5. moved this to 📋 Backlog in Aximprovements Teamon Aug 15, 2026
  6. moved this from 📋 Backlog to 🔖 Ready in Aximprovements Teamon Sep 2, 2026
  7. moved this from 🔖 Ready to 📋 Backlog in Aximprovements Teamon Sep 2, 2026
  8. feanil commented on Nov 30, 2026

    @feanil
    Contributor

    Hit this twice in a row on #337 today, it passed on the third run.

    The second one fits the leaked timer explanation above. The methods playVideo spec is synchronous and never calls the waitUntil helper, so the Timeout has expired failure has to come from a wait that another spec started.

    The part I can't make fit is that neither run has a second failure. The helper's limit and jasmine's own spec timeout are both jasmine.DEFAULT_TIMEOUT_INTERVAL, and the helper counts 50ms per poll rather than measuring elapsed time, so it should always give up after jasmine does. That means the spec that started the wait should fail with Async callback was not invoked first, like in your original report. Both of today's runs only have the one Timeout has expired failure, so I wasn't able to find the spec that started the wait.

  9. farhan commented on Dec 1, 2026

    @farhan
    Contributor

    @salman2013

    I experienced same often.

  10. irfanuddinahmad commented on Dec 2, 2026

    @irfanuddinahmad
    Contributor

    More data from main: the JavaScript Tests workflow failed on 4 of the last 7 pushes, each time on a single Video spec:

    Run Commit Failed spec
    46482864655 7dc8ff8 (11-30) Video HTML5Video non-hls … methods getDuration
    45949904279 332ba2e (11-27) VideoCaption constructor always fetch the transcript in Flash mode
    45407526998 df67a94 (11-24) VideoCaption constructor always fetch the transcript in Flash mode
    45202235829 9b851ba (11-23) Video HTML5Video non-hls … methods _getLogs

    So besides the events: [play] / [ended] cases above, methods getDuration, methods _getLogs and the VideoCaption … Flash mode constructor spec fail intermittently too.

    This matters more soon: openedx/openedx-platform#38750 deletes the platform's copy of these specs, which leaves this repo's CI as the only place they run. A ~50% red rate on main makes real Video regressions easy to miss or re-run past.

    Generated using Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    flaky-test

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions