|  | 
|  | 1 | +package csapi_tests | 
|  | 2 | + | 
|  | 3 | +import ( | 
|  | 4 | +	"testing" | 
|  | 5 | + | 
|  | 6 | +	"github.com/matrix-org/complement/internal/b" | 
|  | 7 | +	"github.com/matrix-org/complement/internal/client" | 
|  | 8 | +) | 
|  | 9 | + | 
|  | 10 | +// Observes "first bug" from https://github.com/matrix-org/dendrite/pull/1394#issuecomment-687056673 | 
|  | 11 | +func TestCumulativeJoinLeaveJoinSync(t *testing.T) { | 
|  | 12 | +	deployment := Deploy(t, b.BlueprintOneToOneRoom) | 
|  | 13 | +	defer deployment.Destroy(t) | 
|  | 14 | + | 
|  | 15 | +	alice := deployment.Client(t, "hs1", "@alice:hs1") | 
|  | 16 | +	bob := deployment.Client(t, "hs1", "@bob:hs1") | 
|  | 17 | + | 
|  | 18 | +	roomID := bob.CreateRoom(t, map[string]interface{}{ | 
|  | 19 | +		"preset": "public_chat", | 
|  | 20 | +	}) | 
|  | 21 | + | 
|  | 22 | +	var since string | 
|  | 23 | + | 
|  | 24 | +	// Get floating next_batch from before joining at all | 
|  | 25 | +	_, since = alice.MustSync(t, client.SyncReq{TimeoutMillis: "0"}) | 
|  | 26 | + | 
|  | 27 | +	alice.JoinRoom(t, roomID, nil) | 
|  | 28 | + | 
|  | 29 | +	// This assumes that sync does not have side-effects in servers. | 
|  | 30 | +	// | 
|  | 31 | +	// The alternative would be to sleep, but that is not acceptable here. | 
|  | 32 | +	sinceJoin := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) | 
|  | 33 | + | 
|  | 34 | +	alice.LeaveRoom(t, roomID) | 
|  | 35 | + | 
|  | 36 | +	sinceLeave := alice.MustSyncUntil(t, client.SyncReq{Since: sinceJoin}, client.SyncLeftFrom(alice.UserID, roomID)) | 
|  | 37 | + | 
|  | 38 | +	alice.JoinRoom(t, roomID, nil) | 
|  | 39 | + | 
|  | 40 | +	alice.MustSyncUntil(t, client.SyncReq{Since: sinceLeave}, client.SyncJoinedTo(alice.UserID, roomID)) | 
|  | 41 | + | 
|  | 42 | +	jsonRes, _ := alice.MustSync(t, client.SyncReq{TimeoutMillis: "0", Since: since}) | 
|  | 43 | +	if jsonRes.Get("rooms.leave." + client.GjsonEscape(roomID)).Exists() { | 
|  | 44 | +		t.Errorf("Incremental sync has joined-left-joined room showing up in leave section, this shouldnt be the case.") | 
|  | 45 | +	} | 
|  | 46 | +} | 
|  | 47 | + | 
|  | 48 | +// Observes "second bug" from https://github.com/matrix-org/dendrite/pull/1394#issuecomment-687056673 | 
|  | 49 | +func TestTentativeEventualJoiningAfterRejecting(t *testing.T) { | 
|  | 50 | +	deployment := Deploy(t, b.BlueprintOneToOneRoom) | 
|  | 51 | +	defer deployment.Destroy(t) | 
|  | 52 | + | 
|  | 53 | +	alice := deployment.Client(t, "hs1", "@alice:hs1") | 
|  | 54 | +	bob := deployment.Client(t, "hs1", "@bob:hs1") | 
|  | 55 | + | 
|  | 56 | +	roomID := alice.CreateRoom(t, map[string]interface{}{ | 
|  | 57 | +		"preset": "public_chat", | 
|  | 58 | +	}) | 
|  | 59 | + | 
|  | 60 | +	var since string | 
|  | 61 | + | 
|  | 62 | +	// Get floating current next_batch | 
|  | 63 | +	_, since = alice.MustSync(t, client.SyncReq{TimeoutMillis: "0"}) | 
|  | 64 | + | 
|  | 65 | +	alice.InviteRoom(t, roomID, bob.UserID) | 
|  | 66 | + | 
|  | 67 | +	bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) | 
|  | 68 | + | 
|  | 69 | +	// This rejects the invite | 
|  | 70 | +	bob.LeaveRoom(t, roomID) | 
|  | 71 | + | 
|  | 72 | +	// Full sync | 
|  | 73 | +	jsonRes, since := bob.MustSync(t, client.SyncReq{TimeoutMillis: "0", FullState: true, Since: since}) | 
|  | 74 | +	if !jsonRes.Get("rooms.leave." + client.GjsonEscape(roomID)).Exists() { | 
|  | 75 | +		t.Errorf("Bob just rejected an invite, it should show up under 'leave' in a full sync") | 
|  | 76 | +	} | 
|  | 77 | + | 
|  | 78 | +	bob.JoinRoom(t, roomID, nil) | 
|  | 79 | + | 
|  | 80 | +	jsonRes, since = bob.MustSync(t, client.SyncReq{TimeoutMillis: "0", FullState: true, Since: since}) | 
|  | 81 | +	if jsonRes.Get("rooms.leave." + client.GjsonEscape(roomID)).Exists() { | 
|  | 82 | +		t.Errorf("Bob has rejected an invite, but then just joined the public room anyways, it should not show up under 'leave' in a full sync %s", since) | 
|  | 83 | +	} | 
|  | 84 | +} | 
0 commit comments