diff options
author | Chocobozzz <me@florianbigard.com> | 2023-05-10 09:28:42 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-05-10 09:30:33 +0200 |
commit | 5170f492b95dc81b75230312411c5fdb0019eed2 (patch) | |
tree | fea18f482e1eb16ac92fd2d08022b33d58ab8747 /shared/server-commands | |
parent | 9d1e41e8bbd9afd961f2dd48c791a3be114e878d (diff) | |
download | PeerTube-5170f492b95dc81b75230312411c5fdb0019eed2.tar.gz PeerTube-5170f492b95dc81b75230312411c5fdb0019eed2.tar.zst PeerTube-5170f492b95dc81b75230312411c5fdb0019eed2.zip |
Try to have more robust live tests
Diffstat (limited to 'shared/server-commands')
-rw-r--r-- | shared/server-commands/videos/live-command.ts | 2 | ||||
-rw-r--r-- | shared/server-commands/videos/streaming-playlists-command.ts | 78 |
2 files changed, 60 insertions, 20 deletions
diff --git a/shared/server-commands/videos/live-command.ts b/shared/server-commands/videos/live-command.ts index dc3c5a86e..2e4bc10b5 100644 --- a/shared/server-commands/videos/live-command.ts +++ b/shared/server-commands/videos/live-command.ts | |||
@@ -224,7 +224,7 @@ export class LiveCommand extends AbstractCommand { | |||
224 | const video = await server.videos.get({ id: videoUUID }) | 224 | const video = await server.videos.get({ id: videoUUID }) |
225 | const hlsPlaylist = video.streamingPlaylists[0] | 225 | const hlsPlaylist = video.streamingPlaylists[0] |
226 | 226 | ||
227 | const shaBody = await server.streamingPlaylists.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url }) | 227 | const shaBody = await server.streamingPlaylists.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url, withRetry: objectStorage }) |
228 | 228 | ||
229 | if (!shaBody[segmentName]) { | 229 | if (!shaBody[segmentName]) { |
230 | throw new Error('Segment SHA does not exist') | 230 | throw new Error('Segment SHA does not exist') |
diff --git a/shared/server-commands/videos/streaming-playlists-command.ts b/shared/server-commands/videos/streaming-playlists-command.ts index 7b92dcc0a..950808b60 100644 --- a/shared/server-commands/videos/streaming-playlists-command.ts +++ b/shared/server-commands/videos/streaming-playlists-command.ts | |||
@@ -44,31 +44,71 @@ export class StreamingPlaylistsCommand extends AbstractCommand { | |||
44 | } | 44 | } |
45 | } | 45 | } |
46 | 46 | ||
47 | getFragmentedSegment (options: OverrideCommandOptions & { | 47 | async getFragmentedSegment (options: OverrideCommandOptions & { |
48 | url: string | 48 | url: string |
49 | range?: string | 49 | range?: string |
50 | |||
51 | withRetry?: boolean // default false | ||
52 | currentRetry?: number | ||
50 | }) { | 53 | }) { |
51 | return unwrapBody<Buffer>(this.getRawRequest({ | 54 | const { withRetry, currentRetry = 1 } = options |
52 | ...options, | 55 | |
53 | 56 | try { | |
54 | url: options.url, | 57 | const result = await unwrapBody<Buffer>(this.getRawRequest({ |
55 | range: options.range, | 58 | ...options, |
56 | implicitToken: false, | 59 | |
57 | responseType: 'application/octet-stream', | 60 | url: options.url, |
58 | defaultExpectedStatus: HttpStatusCode.OK_200 | 61 | range: options.range, |
59 | })) | 62 | implicitToken: false, |
63 | responseType: 'application/octet-stream', | ||
64 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
65 | })) | ||
66 | |||
67 | return result | ||
68 | } catch (err) { | ||
69 | if (!withRetry || currentRetry > 5) throw err | ||
70 | |||
71 | await wait(100) | ||
72 | |||
73 | return this.getFragmentedSegment({ | ||
74 | ...options, | ||
75 | |||
76 | withRetry, | ||
77 | currentRetry: currentRetry + 1 | ||
78 | }) | ||
79 | } | ||
60 | } | 80 | } |
61 | 81 | ||
62 | getSegmentSha256 (options: OverrideCommandOptions & { | 82 | async getSegmentSha256 (options: OverrideCommandOptions & { |
63 | url: string | 83 | url: string |
84 | |||
85 | withRetry?: boolean // default false | ||
86 | currentRetry?: number | ||
64 | }) { | 87 | }) { |
65 | return unwrapBodyOrDecodeToJSON<{ [ id: string ]: string }>(this.getRawRequest({ | 88 | const { withRetry, currentRetry = 1 } = options |
66 | ...options, | 89 | |
67 | 90 | try { | |
68 | url: options.url, | 91 | const result = await unwrapBodyOrDecodeToJSON<{ [ id: string ]: string }>(this.getRawRequest({ |
69 | contentType: 'application/json', | 92 | ...options, |
70 | implicitToken: false, | 93 | |
71 | defaultExpectedStatus: HttpStatusCode.OK_200 | 94 | url: options.url, |
72 | })) | 95 | contentType: 'application/json', |
96 | implicitToken: false, | ||
97 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
98 | })) | ||
99 | |||
100 | return result | ||
101 | } catch (err) { | ||
102 | if (!withRetry || currentRetry > 5) throw err | ||
103 | |||
104 | await wait(100) | ||
105 | |||
106 | return this.getSegmentSha256({ | ||
107 | ...options, | ||
108 | |||
109 | withRetry, | ||
110 | currentRetry: currentRetry + 1 | ||
111 | }) | ||
112 | } | ||
73 | } | 113 | } |
74 | } | 114 | } |