Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f636f96

Browse files
authored
[Impeller] Fix golden flake due to rand use. (#50743)
Now that we're capturing goldens, we shouldn't use `std::rand` here. Explicitly seeded pseudorandom generators offered by the runtime or STL may also result in flakes as the runtime is updated over time.
1 parent 0ebd580 commit f636f96

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -798,12 +798,12 @@ TEST_P(AiksTest, CanRenderTextFrameSTB) {
798798
}
799799

800800
TEST_P(AiksTest, TextFrameSubpixelAlignment) {
801-
std::array<Scalar, 20> phase_offsets;
802-
for (Scalar& offset : phase_offsets) {
803-
auto rand = std::rand(); // NOLINT
804-
offset = (static_cast<float>(rand) / static_cast<float>(RAND_MAX)) * k2Pi;
805-
}
806-
801+
// "Random" numbers between 0 and 1. Hardcoded to avoid flakiness in goldens.
802+
std::array<Scalar, 20> phase_offsets = {
803+
7.82637e-06, 0.131538, 0.755605, 0.45865, 0.532767,
804+
0.218959, 0.0470446, 0.678865, 0.679296, 0.934693,
805+
0.383502, 0.519416, 0.830965, 0.0345721, 0.0534616,
806+
0.5297, 0.671149, 0.00769819, 0.383416, 0.0668422};
807807
auto callback = [&](AiksContext& renderer) -> std::optional<Picture> {
808808
static float font_size = 20;
809809
static float phase_variation = 0.2;
@@ -822,11 +822,12 @@ TEST_P(AiksTest, TextFrameSubpixelAlignment) {
822822
canvas.Scale(GetContentScale());
823823

824824
for (size_t i = 0; i < phase_offsets.size(); i++) {
825-
auto position = Point(
826-
200 + magnitude * std::sin((-phase_offsets[i] * phase_variation +
827-
GetSecondsElapsed() * speed)), //
828-
200 + i * font_size * 1.1 //
829-
);
825+
auto position =
826+
Point(200 + magnitude *
827+
std::sin((-phase_offsets[i] * k2Pi * phase_variation +
828+
GetSecondsElapsed() * speed)), //
829+
200 + i * font_size * 1.1 //
830+
);
830831
if (!RenderTextInCanvasSkia(
831832
GetContext(), canvas,
832833
"the quick brown fox jumped over "

0 commit comments

Comments
 (0)