@@ -112,43 +112,53 @@ func TestBackfillingHistory(t *testing.T) {
112112			eventIDsAfter  :=  createMessagesInRoom (t , alice , roomID , 2 )
113113
114114			// Insert the most recent chunk of backfilled history 
115- 			insertTime1  :=  timeAfterEventBefore .Add (timeBetweenMessages  *  3 )
115+ 			insertTime0  :=  timeAfterEventBefore .Add (timeBetweenMessages  *  3 )
116116			batchSendRes  :=  batchSendHistoricalMessages (
117117				t ,
118118				as ,
119119				roomID ,
120120				eventIdBefore ,
121121				"" ,
122- 				createJoinStateEventsForBackfillRequest ([]string {virtualUserID }, insertTime1 ),
123- 				createMessageEventsForBackfillRequest ([]string {virtualUserID }, insertTime1 , 3 ),
122+ 				createJoinStateEventsForBackfillRequest ([]string {virtualUserID }, insertTime0 ),
123+ 				createMessageEventsForBackfillRequest ([]string {virtualUserID }, insertTime0 , 3 ),
124124				// Status 
125125				200 ,
126126			)
127- 			batchSendResBody  :=  client .ParseJSON (t , batchSendRes )
128- 			historicalEventIDs  :=  getEventsFromBatchSendResponseBody (t , batchSendResBody )
129- 			nextChunkID  :=  getNextChunkIdFromBatchSendResponseBody (t , batchSendResBody )
127+ 			batchSendResBody0  :=  client .ParseJSON (t , batchSendRes )
128+ 			insertionEventID0  :=  client .GetJSONFieldStr (t , batchSendResBody0 , "insertion_event_id" )
129+ 			historicalEventIDs0  :=  client .GetJSONFieldStringArray (t , batchSendResBody0 , "event_ids" )
130+ 			chunkEventID0  :=  client .GetJSONFieldStr (t , batchSendResBody0 , "chunk_event_id" )
131+ 			baseInsertionEventID0  :=  client .GetJSONFieldStr (t , batchSendResBody0 , "base_insertion_event_id" )
132+ 			nextChunkID0  :=  client .GetJSONFieldStr (t , batchSendResBody0 , "next_chunk_id" )
130133
131134			// Insert another older chunk of backfilled history from the same user. 
132135			// Make sure the meta data and joins still work on the subsequent chunk 
133- 			insertTime2  :=  timeAfterEventBefore 
134- 			batchSendRes2  :=  batchSendHistoricalMessages (
136+ 			insertTime1  :=  timeAfterEventBefore 
137+ 			batchSendRes1  :=  batchSendHistoricalMessages (
135138				t ,
136139				as ,
137140				roomID ,
138141				eventIdBefore ,
139- 				nextChunkID ,
140- 				createJoinStateEventsForBackfillRequest ([]string {virtualUserID }, insertTime2 ),
141- 				createMessageEventsForBackfillRequest ([]string {virtualUserID }, insertTime2 , 3 ),
142+ 				nextChunkID0 ,
143+ 				createJoinStateEventsForBackfillRequest ([]string {virtualUserID }, insertTime1 ),
144+ 				createMessageEventsForBackfillRequest ([]string {virtualUserID }, insertTime1 , 3 ),
142145				// Status 
143146				200 ,
144147			)
145- 			batchSendResBody2  :=  client .ParseJSON (t , batchSendRes2 )
146- 			historicalEventIDs2  :=  getEventsFromBatchSendResponseBody (t , batchSendResBody2 )
148+ 			batchSendResBody1  :=  client .ParseJSON (t , batchSendRes1 )
149+ 			insertionEventID1  :=  client .GetJSONFieldStr (t , batchSendResBody1 , "insertion_event_id" )
150+ 			historicalEventIDs1  :=  client .GetJSONFieldStringArray (t , batchSendResBody1 , "event_ids" )
151+ 			chunkEventID1  :=  client .GetJSONFieldStr (t , batchSendResBody1 , "chunk_event_id" )
147152
148153			var  expectedEventIDOrder  []string 
149154			expectedEventIDOrder  =  append (expectedEventIDOrder , eventIDsBefore ... )
150- 			expectedEventIDOrder  =  append (expectedEventIDOrder , historicalEventIDs2 ... )
151- 			expectedEventIDOrder  =  append (expectedEventIDOrder , historicalEventIDs ... )
155+ 			expectedEventIDOrder  =  append (expectedEventIDOrder , insertionEventID1 )
156+ 			expectedEventIDOrder  =  append (expectedEventIDOrder , historicalEventIDs1 ... )
157+ 			expectedEventIDOrder  =  append (expectedEventIDOrder , chunkEventID1 )
158+ 			expectedEventIDOrder  =  append (expectedEventIDOrder , insertionEventID0 )
159+ 			expectedEventIDOrder  =  append (expectedEventIDOrder , historicalEventIDs0 ... )
160+ 			expectedEventIDOrder  =  append (expectedEventIDOrder , chunkEventID0 )
161+ 			expectedEventIDOrder  =  append (expectedEventIDOrder , baseInsertionEventID0 )
152162			expectedEventIDOrder  =  append (expectedEventIDOrder , eventIDsAfter ... )
153163			// Order events from newest to oldest 
154164			expectedEventIDOrder  =  reversed (expectedEventIDOrder )
@@ -228,7 +238,7 @@ func TestBackfillingHistory(t *testing.T) {
228238				200 ,
229239			)
230240			batchSendResBody  :=  client .ParseJSON (t , batchSendRes )
231- 			historicalEventIDs  :=  getEventsFromBatchSendResponseBody (t , batchSendResBody )
241+ 			historicalEventIDs  :=  client . GetJSONFieldStringArray (t , batchSendResBody ,  "event_ids" )
232242
233243			messagesRes  :=  alice .MustDoFunc (t , "GET" , []string {"_matrix" , "client" , "r0" , "rooms" , roomID , "messages" }, client .WithContentType ("application/json" ), client .WithQueries (url.Values {
234244				"dir" :   []string {"b" },
@@ -271,7 +281,7 @@ func TestBackfillingHistory(t *testing.T) {
271281				200 ,
272282			)
273283			batchSendResBody  :=  client .ParseJSON (t , batchSendRes )
274- 			historicalEventIDs  :=  getEventsFromBatchSendResponseBody (t , batchSendResBody )
284+ 			historicalEventIDs  :=  client . GetJSONFieldStringArray (t , batchSendResBody ,  "event_ids" )
275285			backfilledEventId  :=  historicalEventIDs [0 ]
276286
277287			// This is just a dummy event we search for after the backfilledEventId 
@@ -314,7 +324,7 @@ func TestBackfillingHistory(t *testing.T) {
314324				200 ,
315325			)
316326			batchSendResBody  :=  client .ParseJSON (t , batchSendRes )
317- 			stateEventIDs  :=  client .GetJSONFieldStringArray (t , batchSendResBody , "state_events " )
327+ 			stateEventIDs  :=  client .GetJSONFieldStringArray (t , batchSendResBody , "state_event_ids " )
318328
319329			// We only expect 1 state event to be returned because we only passed in 1 
320330			// event into `?state_events_at_start` 
@@ -426,7 +436,7 @@ func TestBackfillingHistory(t *testing.T) {
426436				200 ,
427437			)
428438			batchSendResBody  :=  client .ParseJSON (t , batchSendRes )
429- 			historicalEventIDs  :=  getEventsFromBatchSendResponseBody (t , batchSendResBody )
439+ 			historicalEventIDs  :=  client . GetJSONFieldStringArray (t , batchSendResBody ,  "event_ids" )
430440
431441			messagesRes  :=  alice .MustDoFunc (t , "GET" , []string {"_matrix" , "client" , "r0" , "rooms" , roomID , "messages" }, client .WithContentType ("application/json" ), client .WithQueries (url.Values {
432442				"dir" :   []string {"b" },
@@ -476,7 +486,7 @@ func TestBackfillingHistory(t *testing.T) {
476486				200 ,
477487			)
478488			batchSendResBody  :=  client .ParseJSON (t , batchSendRes )
479- 			historicalEventIDs  :=  getEventsFromBatchSendResponseBody (t , batchSendResBody )
489+ 			historicalEventIDs  :=  client . GetJSONFieldStringArray (t , batchSendResBody ,  "event_ids" )
480490
481491			// Join the room from a remote homeserver after the backfilled messages were sent 
482492			remoteCharlie .JoinRoom (t , roomID , []string {"hs1" })
@@ -548,7 +558,7 @@ func TestBackfillingHistory(t *testing.T) {
548558				200 ,
549559			)
550560			batchSendResBody  :=  client .ParseJSON (t , batchSendRes )
551- 			historicalEventIDs  :=  getEventsFromBatchSendResponseBody (t , batchSendResBody )
561+ 			historicalEventIDs  :=  client . GetJSONFieldStringArray (t , batchSendResBody ,  "event_ids" )
552562
553563			// Join the room from a remote homeserver after the backfilled messages were sent 
554564			remoteCharlie .JoinRoom (t , roomID , []string {"hs1" })
@@ -599,24 +609,24 @@ func TestBackfillingHistory(t *testing.T) {
599609				"limit" : []string {"5" },
600610			}))
601611
612+ 			numMessagesSent  :=  2 
602613			batchSendRes  :=  batchSendHistoricalMessages (
603614				t ,
604615				as ,
605616				roomID ,
606617				eventIdBefore ,
607618				"" ,
608619				createJoinStateEventsForBackfillRequest ([]string {virtualUserID }, timeAfterEventBefore ),
609- 				createMessageEventsForBackfillRequest ([]string {virtualUserID }, timeAfterEventBefore , 2 ),
620+ 				createMessageEventsForBackfillRequest ([]string {virtualUserID }, timeAfterEventBefore , numMessagesSent ),
610621				// Status 
611622				200 ,
612623			)
613624			batchSendResBody  :=  client .ParseJSON (t , batchSendRes )
614- 			historicalEventIDs  :=  getEventsFromBatchSendResponseBody (t , batchSendResBody )
615- 			baseInsertionEventID  :=  historicalEventIDs [ len ( historicalEventIDs ) - 1 ] 
625+ 			historicalEventIDs  :=  client . GetJSONFieldStringArray (t , batchSendResBody ,  "event_ids" )
626+ 			baseInsertionEventID  :=  client . GetJSONFieldStr ( t ,  batchSendResBody ,  "base_insertion_event_id" ) 
616627
617- 			// [1 insertion event + 2 historical events + 1 chunk event + 1 insertion event] 
618- 			if  len (historicalEventIDs ) !=  5  {
619- 				t .Fatalf ("Expected eventID list should be length 5 but saw %d: %v" , len (historicalEventIDs ), historicalEventIDs )
628+ 			if  len (historicalEventIDs ) !=  numMessagesSent  {
629+ 				t .Fatalf ("Expected %d event_ids in the response that correspond to the %d events we sent in the request but saw %d: %s" , numMessagesSent , numMessagesSent , len (historicalEventIDs ), historicalEventIDs )
620630			}
621631
622632			beforeMarkerMessagesRes  :=  remoteCharlie .MustDoFunc (t , "GET" , []string {"_matrix" , "client" , "r0" , "rooms" , roomID , "messages" }, client .WithContentType ("application/json" ), client .WithQueries (url.Values {
@@ -688,24 +698,24 @@ func TestBackfillingHistory(t *testing.T) {
688698			}))
689699
690700			// Historical messages are inserted where we have already scrolled back to 
701+ 			numMessagesSent  :=  2 
691702			batchSendRes  :=  batchSendHistoricalMessages (
692703				t ,
693704				as ,
694705				roomID ,
695706				eventIdBefore ,
696707				"" ,
697708				createJoinStateEventsForBackfillRequest ([]string {virtualUserID }, timeAfterEventBefore ),
698- 				createMessageEventsForBackfillRequest ([]string {virtualUserID }, timeAfterEventBefore , 2 ),
709+ 				createMessageEventsForBackfillRequest ([]string {virtualUserID }, timeAfterEventBefore , numMessagesSent ),
699710				// Status 
700711				200 ,
701712			)
702713			batchSendResBody  :=  client .ParseJSON (t , batchSendRes )
703- 			historicalEventIDs  :=  getEventsFromBatchSendResponseBody (t , batchSendResBody )
704- 			baseInsertionEventID  :=  historicalEventIDs [ len ( historicalEventIDs ) - 1 ] 
714+ 			historicalEventIDs  :=  client . GetJSONFieldStringArray (t , batchSendResBody ,  "event_ids" )
715+ 			baseInsertionEventID  :=  client . GetJSONFieldStr ( t ,  batchSendResBody ,  "base_insertion_event_id" ) 
705716
706- 			// [1 insertion event + 2 historical events + 1 chunk event + 1 insertion event] 
707- 			if  len (historicalEventIDs ) !=  5  {
708- 				t .Fatalf ("Expected eventID list should be length 5 but saw %d: %s" , len (historicalEventIDs ), historicalEventIDs )
717+ 			if  len (historicalEventIDs ) !=  numMessagesSent  {
718+ 				t .Fatalf ("Expected %d event_ids in the response that correspond to the %d events we sent in the request but saw %d: %s" , numMessagesSent , numMessagesSent , len (historicalEventIDs ), historicalEventIDs )
709719			}
710720
711721			beforeMarkerMessagesRes  :=  remoteCharlie .MustDoFunc (t , "GET" , []string {"_matrix" , "client" , "r0" , "rooms" , roomID , "messages" }, client .WithContentType ("application/json" ), client .WithQueries (url.Values {
@@ -783,7 +793,7 @@ func TestBackfillingHistory(t *testing.T) {
783793					200 ,
784794				)
785795				batchSendResBody  :=  client .ParseJSON (t , batchSendRes )
786- 				historicalEventIDs  :=  getEventsFromBatchSendResponseBody (t , batchSendResBody )
796+ 				historicalEventIDs  :=  client . GetJSONFieldStringArray (t , batchSendResBody ,  "event_ids" )
787797
788798				messagesRes  :=  alice .MustDoFunc (t , "GET" , []string {"_matrix" , "client" , "r0" , "rooms" , roomID , "messages" }, client .WithContentType ("application/json" ), client .WithQueries (url.Values {
789799					"dir" :   []string {"b" },
@@ -823,10 +833,9 @@ func TestBackfillingHistory(t *testing.T) {
823833					200 ,
824834				)
825835				batchSendResBody  :=  client .ParseJSON (t , batchSendRes )
826- 				historicalEventIDs  :=  getEventsFromBatchSendResponseBody (t , batchSendResBody )
827- 				insertionEventID  :=  historicalEventIDs [0 ]
828- 				chunkEventID  :=  historicalEventIDs [2 ]
829- 				baseInsertionEventID  :=  historicalEventIDs [3 ]
836+ 				insertionEventID  :=  client .GetJSONFieldStr (t , batchSendResBody , "insertion_event_id" )
837+ 				chunkEventID  :=  client .GetJSONFieldStr (t , batchSendResBody , "chunk_event_id" )
838+ 				baseInsertionEventID  :=  client .GetJSONFieldStr (t , batchSendResBody , "base_insertion_event_id" )
830839
831840				// Send the marker event 
832841				markerEventID  :=  sendMarkerAndEnsureBackfilled (t , as , alice , roomID , baseInsertionEventID )
@@ -1151,15 +1160,3 @@ func batchSendHistoricalMessages(
11511160
11521161	return  res 
11531162}
1154- 
1155- func  getEventsFromBatchSendResponseBody (t  * testing.T , body  []byte ) (eventIDs  []string ) {
1156- 	eventIDs  =  client .GetJSONFieldStringArray (t , body , "events" )
1157- 
1158- 	return  eventIDs 
1159- }
1160- 
1161- func  getNextChunkIdFromBatchSendResponseBody (t  * testing.T , body  []byte ) (nextChunkID  string ) {
1162- 	nextChunkID  =  client .GetJSONFieldStr (t , body , "next_chunk_id" )
1163- 
1164- 	return  nextChunkID 
1165- }
0 commit comments