@@ -144,7 +144,7 @@ func performSync(t ct.TestLike, cli *client.CSAPI, useSimplifiedSlidingSync bool
144144func gatherSyncResults (t ct.TestLike , cli * client.CSAPI , useSimplifiedSlidingSync bool , roomID , stopAtEventID string ) syncResponse {
145145 t .Helper ()
146146 start := time .Now ()
147- timeout := 5 * time .Second
147+ timeout := 10 * time .Second
148148 var gatheredResponse syncResponse
149149 var since string
150150 var stop bool
@@ -406,7 +406,7 @@ func TestStickyEventsIgnoreHistoryVisibility(t *testing.T) {
406406 })
407407}
408408
409- func xTestStickyEventsSentToNewlyJoinedServers (t * testing.T ) {
409+ func TestStickyEventsSentToNewlyJoinedServers (t * testing.T ) {
410410 deployment := complement .Deploy (t , 3 )
411411 defer deployment .Destroy (t )
412412
@@ -432,15 +432,17 @@ func xTestStickyEventsSentToNewlyJoinedServers(t *testing.T) {
432432 "body" : "ALICE This is a sticky event which is beyond the timeline limit" ,
433433 },
434434 }, withStickyDuration (duration ))
435+ bob .MustSyncUntil (t , client.SyncReq {}, client .SyncTimelineHasEventID (roomID , aliceStickyEventIDNotInTimeline ))
435436 bobStickyEventIDNotInTimeline := sendStickyEvent (t , bob , roomID , b.Event {
436437 Type : "m.room.message" ,
437438 Content : map [string ]interface {}{
438439 "msgtype" : "m.text" ,
439440 "body" : "BOB This is a sticky event which is beyond the timeline limit" ,
440441 },
441442 }, withStickyDuration (duration ))
443+ alice .MustSyncUntil (t , client.SyncReq {}, client .SyncTimelineHasEventID (roomID , bobStickyEventIDNotInTimeline ))
442444 for i := 0 ; i < 25 ; i ++ {
443- alice .Unsafe_SendEventUnsynced (t , roomID , b.Event {
445+ alice .SendEventSynced (t , roomID , b.Event {
444446 Type : "m.room.message" ,
445447 Content : map [string ]interface {}{
446448 "msgtype" : "m.text" ,
@@ -455,27 +457,52 @@ func xTestStickyEventsSentToNewlyJoinedServers(t *testing.T) {
455457 "body" : "ALICE This is a sticky event which is inside the timeline limit" ,
456458 },
457459 }, withStickyDuration (duration ))
460+ bob .MustSyncUntil (t , client.SyncReq {}, client .SyncTimelineHasEventID (roomID , aliceStickyEventIDInTimeline ))
458461 bobStickyEventIDInTimeline := sendStickyEvent (t , bob , roomID , b.Event {
459462 Type : "m.room.message" ,
460463 Content : map [string ]interface {}{
461464 "msgtype" : "m.text" ,
462465 "body" : "BOB This is a sticky event which is inside the timeline limit" ,
463466 },
464467 }, withStickyDuration (duration ))
468+ alice .MustSyncUntil (t , client.SyncReq {}, client .SyncTimelineHasEventID (roomID , bobStickyEventIDInTimeline ))
465469
466470 newJoiner .MustJoinRoom (t , roomID , []spec.ServerName {"hs1" })
467471
468472 // wait until hs1 and hs2 see the join, as this will trigger the sending of sticky events
469473 alice .MustSyncUntil (t , client.SyncReq {}, client .SyncJoinedTo (newJoiner .UserID , roomID ))
470474 bob .MustSyncUntil (t , client.SyncReq {}, client .SyncJoinedTo (newJoiner .UserID , roomID ))
471-
475+ t .Logf ("alice's sticky events early=%s latest=%s" , aliceStickyEventIDNotInTimeline , aliceStickyEventIDInTimeline )
476+ t .Logf ("bob's sticky events early=%s latest=%s" , bobStickyEventIDNotInTimeline , bobStickyEventIDInTimeline )
477+
478+ // we need to wait for 2 things to happen:
479+ // - Alice to send her sticky events
480+ // - Bob to send his sticky events
481+ // But we don't want to use stop events for both, because we want to make sure that servers PROACTIVELY
482+ // send sticky events. In particular, perhaps Alice and Bob send their sticky events to NewJoiner but NewJoiner
483+ // puts them into a staging area and doesn't process them yet because they haven't processed the /send_join response
484+ // by the time they get the sticky events. We must make sure that NewJoiner processes this staging area without waiting
485+ // for another event. Sending a stop event will cause the queue for that server to be processed,
486+ // masking the problem. As a result, we will:
487+ // - send a stop event from alice and wait until we see the stop event.
488+ // - wait until we see bob's latest sticky event (no stop event)
472489 stopEventID := alice .Unsafe_SendEventUnsynced (t , roomID , stopMsg )
473-
474490 syncResp := gatherSyncResults (t , newJoiner , useSimplifiedSlidingSync , roomID , stopEventID )
475- mustHaveStickyEventID (t , aliceStickyEventIDInTimeline , syncResp .stickyEvents )
476- mustHaveStickyEventID (t , aliceStickyEventIDNotInTimeline , syncResp .stickyEvents )
477- mustHaveStickyEventID (t , bobStickyEventIDInTimeline , syncResp .stickyEvents )
478- mustHaveStickyEventID (t , bobStickyEventIDNotInTimeline , syncResp .stickyEvents )
491+ allEvents := append (syncResp .stickyEvents , syncResp .timelineEvents ... )
492+ // TODO: sometimes this fails because we seem to omit it from the sync response, but server logs suggest it is put in the timeline..?
493+ syncResp2 := gatherSyncResults (t , newJoiner , useSimplifiedSlidingSync , roomID , bobStickyEventIDInTimeline )
494+ allEvents = append (allEvents , syncResp2 .timelineEvents ... ) // will have dupe events but this is fine.
495+ allEvents = append (allEvents , syncResp2 .stickyEvents ... )
496+ // we don't know which section they will appear in as it depends on many factors like:
497+ // - if the server automatically backfills from their join event, the latest sticky events will be in the timeline
498+ // - if other servers /send sticky events before the backfill, they will appear in 'sticky', else they will
499+ // appear after the initial backfill so be in the timeline. This may or may not push out the latest sticky
500+ // events depending on how far back they /get_missing_events.
501+ // as a result, we're just happy to see the sticky events, and don't care where they appear.
502+ mustHaveStickyEventID (t , aliceStickyEventIDInTimeline , allEvents )
503+ mustHaveStickyEventID (t , aliceStickyEventIDNotInTimeline , allEvents )
504+ mustHaveStickyEventID (t , bobStickyEventIDInTimeline , allEvents )
505+ mustHaveStickyEventID (t , bobStickyEventIDNotInTimeline , allEvents )
479506 })
480507}
481508
@@ -525,6 +552,7 @@ func TestSoftFailedStickyEvents(t *testing.T) {
525552 // now we rejoin bob.
526553 // This should cause soft-failure of sticky events to be re-evaluated, causing it to appear in the 'sticky' section.
527554 bob .MustJoinRoom (t , roomID , []spec.ServerName {"hs1" })
555+ alice .MustSyncUntil (t , client.SyncReq {}, client .SyncJoinedTo (bob .UserID , roomID ))
528556 forEachSync (t , func (t * testing.T , useSimplifiedSlidingSync bool ) {
529557 syncResp := gatherSyncResults (t , alice , useSimplifiedSlidingSync , roomID , stickyEventID )
530558 mustHaveStickyEventID (t , stickyEventID , syncResp .stickyEvents )
0 commit comments