@@ -34,7 +34,9 @@ afterAll(async () => {
3434} , 120_000 ) ;
3535
3636const STREAM_ID = "browserPreview" ;
37- const PART_ID = "part-1" ;
37+ const PART_ID = "part" ;
38+ const FRAME_BYTES = 250 * 1024 ;
39+ const FRAME_COUNT = 8 ;
3840
3941/** Mirrors `S2RealtimeStreams.toStreamName` on the shared-basin prefix. */
4042function runStreamName ( p : {
@@ -52,6 +54,12 @@ function redisStreamKey(runId: string, streamId: string): string {
5254 return `tr:realtime:streams:stream:${ runId } :${ streamId } ` ;
5355}
5456
57+ function framesFound ( body : string ) : number {
58+ return Array . from ( { length : FRAME_COUNT } , ( _ , i ) => `${ PART_ID } -${ i } ` ) . filter ( ( id ) =>
59+ body . includes ( id )
60+ ) . length ;
61+ }
62+
5563async function s2Body ( streamName : string ) : Promise < string > {
5664 const qs = new URLSearchParams ( { seq_num : "0" , clamp : "true" , wait : "0" } ) ;
5765 const res = await fetch (
@@ -96,20 +104,24 @@ describe("session runs and the realtime streams backend", () => {
96104 select : { friendlyId : true , realtimeStreamsVersion : true , streamBasinName : true } ,
97105 } ) ;
98106
99- const appendRes = await fetch (
100- `${ server . webapp . baseUrl } /realtime/v1/streams/${ created . runId } /self/${ STREAM_ID } /append` ,
101- {
102- method : "POST" ,
103- headers : {
104- Authorization : `Bearer ${ apiKey } ` ,
105- "Content-Type" : "text/plain" ,
106- "X-Part-Id" : PART_ID ,
107- } ,
108- body : JSON . stringify ( { frame : "a" . repeat ( 1024 ) } ) ,
109- }
110- ) ;
111-
112- expect ( appendRes . status ) . toBe ( 200 ) ;
107+ const appendStatuses : number [ ] = [ ] ;
108+ for ( let i = 0 ; i < FRAME_COUNT ; i ++ ) {
109+ const res = await fetch (
110+ `${ server . webapp . baseUrl } /realtime/v1/streams/${ created . runId } /self/${ STREAM_ID } /append` ,
111+ {
112+ method : "POST" ,
113+ headers : {
114+ Authorization : `Bearer ${ apiKey } ` ,
115+ "Content-Type" : "text/plain" ,
116+ "X-Part-Id" : `${ PART_ID } -${ i } ` ,
117+ } ,
118+ body : JSON . stringify ( { i, frame : "a" . repeat ( FRAME_BYTES ) } ) ,
119+ }
120+ ) ;
121+ appendStatuses . push ( res . status ) ;
122+ }
123+
124+ expect ( appendStatuses ) . toEqual ( Array . from ( { length : FRAME_COUNT } , ( ) => 200 ) ) ;
113125
114126 const streamName = runStreamName ( {
115127 orgId : organization . id ,
@@ -119,17 +131,17 @@ describe("session runs and the realtime streams backend", () => {
119131 streamId : STREAM_ID ,
120132 } ) ;
121133 const redis = new Redis ( { host : server . redis . host , port : server . redis . port } ) ;
122- let observed : { version : string ; recordsInS2 : boolean ; keyInRedis : boolean } ;
134+ let observed : { version : string ; framesInS2 : number ; keyInRedis : boolean } ;
123135 try {
124136 observed = {
125137 version : run . realtimeStreamsVersion ,
126- recordsInS2 : ( await s2Body ( streamName ) ) . includes ( PART_ID ) ,
138+ framesInS2 : framesFound ( await s2Body ( streamName ) ) ,
127139 keyInRedis : ( await redis . exists ( redisStreamKey ( created . runId , STREAM_ID ) ) ) === 1 ,
128140 } ;
129141 } finally {
130142 redis . disconnect ( ) ;
131143 }
132144
133- expect ( observed ) . toEqual ( { version : "v2" , recordsInS2 : true , keyInRedis : false } ) ;
145+ expect ( observed ) . toEqual ( { version : "v2" , framesInS2 : FRAME_COUNT , keyInRedis : false } ) ;
134146 } ) ;
135147} ) ;
0 commit comments