Repository navigation
Commit 0bfba40
fix: let the player asserts wait for the bus instead of reading once (#218)
OCPPlayerHarness.play() emits on the bus and sleeps a fixed 50ms, and
assert_player_state then reads self.player.state once. The emit returns
immediately and the player transitions on another thread, so the read
lands before the transition whenever the box is busy. "Not yet" and
"wrong" are different answers and one read cannot tell them apart.
Measured in ovos-media-plugin-chromecast at its dev: 4 failures in 12 runs,
always test_play_pause_resume_stop_through_ocp, always the first assert
after play(). Replacing only that assert with a polling one, through a
throwaway conftest and with nothing else changed, took it to 0 in 12. That
is what identifies the cause.
This adds settle_timeout and one _eventually() helper, and routes the six
state asserts through it. It returns as soon as the value matches, so a
passing assert costs nothing and the suite does not slow down; on timeout
it raises the message it raised before, the time it waited and the
deadline it waited to. All six say this, because _eventually appends it
once instead of each message spelling it.
With this branch installed, chromecast reports 0 failures in 12 runs of the
pair and 0 in 12 of the whole directory, with no local conftest.
A polling assert that always passed would be worse than the flake, so the
control matters: driving the harness with nothing played and asserting
PLAYING still fails, after 2.01s, naming the state it actually read.
The review of this branch asked for two things, and they are in this
commit. First, every test pinned _eventually directly and nothing pinned
that the six asserts route through it: reverting assert_player_state to a
single read left the new file green. test_five_asserts_wait_the_class_
timeout_before_they_fail now calls each of the six on a player that never
transitions, with the class settle_timeout patched small, and asserts on
the elapsed time, so a single read fails it. Second, a widened default
was not caught: the deadline tests build their own timeout, so
settle_timeout = 30.0 passed. The default is now bounded to 0.5s..5.0s,
because six asserts share the number and a silent widening turns a
two-second answer into a suite that takes minutes to say the same thing.
Three mutations, new file run against each: helper loop removed 3 failed,
settle_timeout = 30.0 1 failed, assert_player_state single read 1 failed.
The last two passed before this commit.
The two backend booleans also dropped the value they were handed, so
their timeout message could not say what was read. They now name
is_playing and is_paused.
The time.sleep(0.05) calls in the transport methods are left alone. With
the asserts polling they are redundant, but removing them is a wider change
to a shared harness and buys 50ms.
Co-authored-by: JarbasAi <jarbasai@mailfence.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>1 parent a1df882 commit 0bfba40
2 files changed
Lines changed: 229 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
581 | 581 | | |
582 | 582 | | |
583 | 583 | | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
584 | 610 | | |
585 | | - | |
| 611 | + | |
586 | 612 | | |
587 | 613 | | |
588 | 614 | | |
589 | 615 | | |
590 | | - | |
591 | | - | |
592 | | - | |
593 | | - | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
594 | 620 | | |
595 | 621 | | |
596 | | - | |
| 622 | + | |
597 | 623 | | |
598 | 624 | | |
599 | 625 | | |
600 | 626 | | |
601 | | - | |
602 | | - | |
603 | | - | |
604 | | - | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
605 | 631 | | |
606 | 632 | | |
607 | | - | |
608 | | - | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
609 | 637 | | |
610 | 638 | | |
611 | | - | |
612 | | - | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
613 | 643 | | |
614 | 644 | | |
615 | | - | |
616 | | - | |
617 | | - | |
618 | | - | |
619 | | - | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
620 | 651 | | |
621 | 652 | | |
622 | | - | |
| 653 | + | |
623 | 654 | | |
624 | 655 | | |
625 | 656 | | |
626 | 657 | | |
627 | | - | |
628 | | - | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
629 | 662 | | |
630 | 663 | | |
631 | 664 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
0 commit comments