Skip to content

Commit

Permalink
Add testclient to check bug
Browse files Browse the repository at this point in the history
  • Loading branch information
corny committed Sep 4, 2023
1 parent 14b47a0 commit acd97a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func (c *Client) downloadChunked(ctx context.Context, req *http.Request, w *io.P
for i := 0; i < maxRoutines; i++ {
go func() {
i := int(currentChunk.Add(1)) - 1
if i > len(chunks) {
if i >= len(chunks) {
// no more chunks
return
}
Expand Down
11 changes: 10 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ func TestGetVideoWithManifestURL(t *testing.T) {
func TestGetStream(t *testing.T) {
assert, require := assert.New(t), require.New(t)

expectedSize := 988479

// Create testclient to enforce re-using of routines
testClient := Client{
Debug: true,
MaxRoutines: 10,
ChunkSize: int64(expectedSize) / 11,
}

// Download should not last longer than a minute.
// Otherwise we assume Youtube is throtteling us.
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
Expand All @@ -141,7 +150,7 @@ func TestGetStream(t *testing.T) {

reader, size, err := testClient.GetStreamContext(ctx, video, &video.Formats[0])
require.NoError(err)
assert.EqualValues(988479, size)
assert.EqualValues(expectedSize, size)

data, err := io.ReadAll(reader)
require.NoError(err)
Expand Down

0 comments on commit acd97a6

Please sign in to comment.