Live video on the AT Protocol
at eli/postgres 100 lines 3.0 kB view raw
1package media 2 3import ( 4 "bytes" 5 "context" 6 "fmt" 7 "io" 8 "os" 9 "testing" 10 11 "github.com/stretchr/testify/require" 12 "golang.org/x/sync/errgroup" 13 "stream.place/streamplace/test/remote" 14) 15 16func TestThumbnail(t *testing.T) { 17 withNoGSTLeaks(t, func() { 18 // Open input file 19 inputFile, err := os.Open(getFixture("sample-segment.mp4")) 20 require.NoError(t, err) 21 defer inputFile.Close() 22 bs, err := io.ReadAll(inputFile) 23 require.NoError(t, err) 24 25 ctx := context.Background() 26 g, ctx := errgroup.WithContext(ctx) 27 28 for i := 0; i < streamplaceTestCount; i++ { 29 g.Go(func() error { 30 thumbnail := bytes.Buffer{} 31 // thumbnailCtx = log.WithDebugValue(ctx, map[string]map[string]int{"function": {"Thumbnail": 9}}) 32 err := Thumbnail(ctx, bytes.NewReader(bs), &thumbnail, "png") 33 if err != nil { 34 return err 35 } 36 if thumbnail.Len() == 0 { 37 return fmt.Errorf("thumbnail buffer is empty") 38 } 39 require.Equal(t, 1418910, thumbnail.Len()) 40 return nil 41 }) 42 g.Go(func() error { 43 thumbnail := bytes.Buffer{} 44 // thumbnailCtx = log.WithDebugValue(ctx, map[string]map[string]int{"function": {"Thumbnail": 9}}) 45 err := Thumbnail(ctx, bytes.NewReader(bs), &thumbnail, "jpeg") 46 if err != nil { 47 return err 48 } 49 if thumbnail.Len() == 0 { 50 return fmt.Errorf("thumbnail buffer is empty") 51 } 52 // jpeg thumbnails aren't deterministic, so let's give a range instead 53 // testing gave 140969 bytes, but it can vary a bit 54 require.Greater(t, thumbnail.Len(), 140000) 55 require.Less(t, thumbnail.Len(), 150000) 56 require.Equal(t, 140969, thumbnail.Len()) 57 return nil 58 }) 59 } 60 61 err = g.Wait() 62 require.NoError(t, err) 63 }) 64} 65 66// This segment once caused a segfault in gst-libav. 67// It doesn't gotta work but it does gotta not crash. 68func TestThumbnailKryptonite(t *testing.T) { 69 withNoGSTLeaks(t, func() { 70 inputFile, err := os.Open(remote.RemoteFixture("46c876d5e6c4124275b8856431833adaad31cb5246caca8ded9dc4d37de400a4/kryptonite-screenshot.mp4")) 71 require.NoError(t, err) 72 defer inputFile.Close() 73 bs, err := io.ReadAll(inputFile) 74 require.NoError(t, err) 75 76 thumbnail := bytes.Buffer{} 77 err = Thumbnail(context.Background(), bytes.NewReader(bs), &thumbnail, "png") 78 require.NoError(t, err) 79 require.Equal(t, 561486, thumbnail.Len()) 80 }) 81} 82 83// This segment once caused the jpeg encoder to stall. 84// So now we have snapshot=false. 85func TestThumbnailStall(t *testing.T) { 86 withNoGSTLeaks(t, func() { 87 inputFile, err := os.Open(remote.RemoteFixture("aef704b702d24de7cf2ae453f4def763f3b39f4f353c8a1602f59cb995aafb53/broken-thumbnail.mp4")) 88 require.NoError(t, err) 89 defer inputFile.Close() 90 bs, err := io.ReadAll(inputFile) 91 require.NoError(t, err) 92 thumbnail := bytes.Buffer{} 93 err = Thumbnail(context.Background(), bytes.NewReader(bs), &thumbnail, "jpeg") 94 require.NoError(t, err) 95 // This is inconsistent. Which is concerning. 96 // Testing gave ~22000 bytes 97 require.Greater(t, thumbnail.Len(), 20000) 98 require.Less(t, thumbnail.Len(), 25000) 99 }) 100}