Skip to content

Commit c1c9a07

Browse files
amtiYoclaude
andcommitted
test: keep the encoding tests fast under the race detector
The morning animation test draws one loop and is skipped under -race, where it took minutes. The order of frames drawn at once is checked on a tiny scene instead, which the race detector does see. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 4ad7069 commit c1c9a07

4 files changed

Lines changed: 60 additions & 5 deletions

File tree

‎internal/anim/anim_test.go‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
package anim
33

44
import (
5+
"bytes"
6+
"context"
57
"image"
68
"image/color"
79
"math"
@@ -213,3 +215,31 @@ func BenchmarkMorningFrame(b *testing.B) {
213215
s.Draw(c, 3+float64(i%240)/FPS)
214216
}
215217
}
218+
219+
// counter paints frame i in grey level i, so the raw stream shows the order.
220+
type counter struct{}
221+
222+
func (counter) Size() (int, int) { return 8, 4 }
223+
func (counter) Duration() float64 { return 2 }
224+
func (counter) Draw(c *Canvas, t float64) {
225+
v := float32(math.Round(t*FPS)) / 255
226+
c.Fill(RGB{v, v, v})
227+
}
228+
229+
// Frames drawn at once are written in order, every one of them.
230+
func TestFramesComeInOrder(t *testing.T) {
231+
var out bytes.Buffer
232+
st, err := frames(context.Background(), counter{}, 7, &out)
233+
if err != nil {
234+
t.Fatal(err)
235+
}
236+
const size = 3 * 8 * 4
237+
if st.Frames != 60 || out.Len() != 60*size {
238+
t.Fatalf("%d frames, %d bytes", st.Frames, out.Len())
239+
}
240+
for i := range 60 {
241+
if got := out.Bytes()[i*size]; int(got) != i {
242+
t.Fatalf("frame %d holds frame %d", i, got)
243+
}
244+
}
245+
}

‎internal/schedule/animate_test.go‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ func TestMorningAnimationOnceADay(t *testing.T) {
109109
if err != nil {
110110
t.Skip("no ffmpeg")
111111
}
112+
if raceEnabled {
113+
t.Skip("encoding under the race detector takes minutes")
114+
}
112115
dir := t.TempDir()
113116
img := image.NewRGBA(image.Rect(0, 0, 128, 64))
114117
for y := range 64 {
@@ -125,11 +128,13 @@ func TestMorningAnimationOnceADay(t *testing.T) {
125128
}
126129
f.Close()
127130

131+
// One animator for the day, as in the service: it draws once.
132+
animator := &Animator{FFmpeg: ffmpeg}
133+
rd := db.Round{Date: round.NewDate(2026, 11, 2), DayNo: 4, PlaceID: 1}
128134
send := func(kind string, refuse bool, chats ...int64) *animTG {
129135
tgc := &animTG{refuse: refuse}
130136
s, _ := resultSender(nil, panoStore{kind: kind})
131-
s.TG, s.ImagesDir, s.Anim = tgc, dir, &Animator{FFmpeg: ffmpeg}
132-
rd := db.Round{Date: round.NewDate(2026, 11, 2), DayNo: 4, PlaceID: 1}
137+
s.TG, s.ImagesDir, s.Anim = tgc, dir, animator
133138
for _, c := range chats {
134139
if _, err := s.sendPost(context.Background(), c, rd, "caption", nil); err != nil {
135140
t.Fatal(err)
@@ -141,10 +146,14 @@ func TestMorningAnimationOnceADay(t *testing.T) {
141146
if len(tgc.animations) != 2 || len(tgc.animations[0].MP4) == 0 || tgc.animations[1].FileID != "A1" || len(tgc.photos) != 0 {
142147
t.Fatalf("animations %d, photos %d", len(tgc.animations), len(tgc.photos))
143148
}
149+
// Telegram refusing the file sends the photo, and the other chats go
150+
// straight to the photo.
151+
if tgc := send("panorama", true, 3, 4); len(tgc.photos) != 2 {
152+
t.Fatalf("refused: photos %d", len(tgc.photos))
153+
}
154+
// A photo place never tries.
155+
rd.Date = rd.Date.AddDays(1)
144156
if tgc := send("photo", false, 1); len(tgc.animations) != 0 || len(tgc.photos) != 1 {
145157
t.Fatalf("photo place: animations %d, photos %d", len(tgc.animations), len(tgc.photos))
146158
}
147-
if tgc := send("panorama", true, 1, 2); len(tgc.photos) != 2 {
148-
t.Fatalf("refused: photos %d", len(tgc.photos))
149-
}
150159
}

‎internal/schedule/norace_test.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
//go:build !race
4+
5+
package schedule
6+
7+
const raceEnabled = false

‎internal/schedule/race_test.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
//go:build race
4+
5+
package schedule
6+
7+
// raceEnabled skips the tests that encode a whole animation: under the race
8+
// detector one takes minutes.
9+
const raceEnabled = true

0 commit comments

Comments
 (0)