@@ -94,7 +94,7 @@ def test_count_devices_by_users(self):
94
94
def test_get_device_updates_by_remote (self ):
95
95
device_ids = ["device_id1" , "device_id2" ]
96
96
97
- # Add two device updates with a single stream_id
97
+ # Add two device updates with sequential ` stream_id`s
98
98
self .get_success (
99
99
self .store .add_device_change_to_streams ("user_id" , device_ids , ["somehost" ])
100
100
)
@@ -107,6 +107,54 @@ def test_get_device_updates_by_remote(self):
107
107
# Check original device_ids are contained within these updates
108
108
self ._check_devices_in_updates (device_ids , device_updates )
109
109
110
+ def test_get_device_updates_by_remote_can_limit_properly (self ):
111
+ """
112
+ Tests that `get_device_updates_by_remote` returns an appropriate
113
+ stream_id to resume fetching from (without skipping any results).
114
+ """
115
+
116
+ # Add some device updates with sequential `stream_id`s
117
+ device_ids = [
118
+ "device_id1" ,
119
+ "device_id2" ,
120
+ "device_id3" ,
121
+ "device_id4" ,
122
+ "device_id5" ,
123
+ ]
124
+ self .get_success (
125
+ self .store .add_device_change_to_streams ("user_id" , device_ids , ["somehost" ])
126
+ )
127
+
128
+ # Get all device updates ever meant for this remote
129
+ next_stream_id , device_updates = self .get_success (
130
+ self .store .get_device_updates_by_remote ("somehost" , - 1 , limit = 3 )
131
+ )
132
+
133
+ # Check the first three original device_ids are contained within these updates
134
+ self ._check_devices_in_updates (device_ids [:3 ], device_updates )
135
+
136
+ # Get the next batch of device updates
137
+ next_stream_id , device_updates = self .get_success (
138
+ self .store .get_device_updates_by_remote ("somehost" , next_stream_id , limit = 3 )
139
+ )
140
+
141
+ # Check the last two original device_ids are contained within these updates
142
+ self ._check_devices_in_updates (device_ids [3 :], device_updates )
143
+
144
+ # Add some more device updates to ensure it still resumes properly
145
+ device_ids = ["device_id6" , "device_id7" ]
146
+ self .get_success (
147
+ self .store .add_device_change_to_streams ("user_id" , device_ids , ["somehost" ])
148
+ )
149
+
150
+ # Get the next batch of device updates
151
+ next_stream_id , device_updates = self .get_success (
152
+ self .store .get_device_updates_by_remote ("somehost" , next_stream_id , limit = 3 )
153
+ )
154
+
155
+ # Check the newly-added device_ids are contained within these updates
156
+ self ._check_devices_in_updates (device_ids , device_updates )
157
+
110
158
def _check_devices_in_updates (self , expected_device_ids , device_updates ):
111
159
"""Check that an specific device ids exist in a list of device update EDUs"""
112
160
self .assertEqual (len (device_updates ), len (expected_device_ids ))
0 commit comments