@@ -173,9 +173,8 @@ def test_context_get_remaining_time_in_three_seconds(self):
173
173
with self .create_container (params , image ):
174
174
r = self .invoke_function ()
175
175
176
- # Execution time is not decided, 1.0s ~ 3.0s is a good estimation
177
- self .assertLess (int (r .content ), 3000 )
178
- self .assertGreater (int (r .content ), 1000 )
176
+ # Execution time is not decided, but it should be around 2.0s
177
+ self .assertAround (int (r .content ), 2000 )
179
178
180
179
181
180
def test_context_get_remaining_time_in_ten_seconds (self ):
@@ -186,9 +185,8 @@ def test_context_get_remaining_time_in_ten_seconds(self):
186
185
with self .create_container (params , image ):
187
186
r = self .invoke_function ()
188
187
189
- # Execution time is not decided, 8.0s ~ 10.0s is a good estimation
190
- self .assertLess (int (r .content ), 10000 )
191
- self .assertGreater (int (r .content ), 8000 )
188
+ # Execution time is not decided, but it should be around 9.0s
189
+ self .assertAround (int (r .content ), 9000 )
192
190
193
191
194
192
def test_context_get_remaining_time_in_default_deadline (self ):
@@ -199,9 +197,8 @@ def test_context_get_remaining_time_in_default_deadline(self):
199
197
with self .create_container (params , image ):
200
198
r = self .invoke_function ()
201
199
202
- # Executation time is not decided, 298.0s ~ 300.0s is a good estimation
203
- self .assertLess (int (r .content ), 300000 )
204
- self .assertGreater (int (r .content ), 298000 )
200
+ # Execution time is not decided, but it should be around 299.0s
201
+ self .assertAround (int (r .content ), 299000 )
205
202
206
203
207
204
def test_invoke_with_pre_runtime_api_runtime (self ):
@@ -256,6 +253,13 @@ def test_custom_client_context(self):
256
253
self .assertEqual ("bar" , content ["foo" ])
257
254
self .assertEqual (123 , content ["baz" ])
258
255
256
+ def assertAround (self , number , target ):
257
+ # Emulating arm64 on x86 causes the invoke to take longer
258
+ delay_arm64 = 500
259
+ actual_target = target if self .ARCH != 'arm64' else target - delay_arm64
260
+
261
+ self .assertLess (number , actual_target + 1000 )
262
+ self .assertGreater (number , actual_target - 1000 )
259
263
260
264
if __name__ == "__main__" :
261
265
main ()
0 commit comments