@@ -172,9 +172,8 @@ def test_context_get_remaining_time_in_three_seconds(self):
172172 with self .create_container (params , image ):
173173 r = self .invoke_function ()
174174
175- # Execution time is not decided, 1.0s ~ 3.0s is a good estimation
176- self .assertLess (int (r .content ), 3000 )
177- self .assertGreater (int (r .content ), 1000 )
175+ # Execution time is not decided, but it should be around 2.0s
176+ self .assertAround (int (r .content ), 2000 )
178177
179178
180179 def test_context_get_remaining_time_in_ten_seconds (self ):
@@ -185,9 +184,8 @@ def test_context_get_remaining_time_in_ten_seconds(self):
185184 with self .create_container (params , image ):
186185 r = self .invoke_function ()
187186
188- # Execution time is not decided, 8.0s ~ 10.0s is a good estimation
189- self .assertLess (int (r .content ), 10000 )
190- self .assertGreater (int (r .content ), 8000 )
187+ # Execution time is not decided, but it should be around 9.0s
188+ self .assertAround (int (r .content ), 9000 )
191189
192190
193191 def test_context_get_remaining_time_in_default_deadline (self ):
@@ -198,9 +196,8 @@ def test_context_get_remaining_time_in_default_deadline(self):
198196 with self .create_container (params , image ):
199197 r = self .invoke_function ()
200198
201- # Executation time is not decided, 298.0s ~ 300.0s is a good estimation
202- self .assertLess (int (r .content ), 300000 )
203- self .assertGreater (int (r .content ), 298000 )
199+ # Execution time is not decided, but it should be around 299.0s
200+ self .assertAround (int (r .content ), 299000 )
204201
205202
206203 def test_invoke_with_pre_runtime_api_runtime (self ):
@@ -291,5 +288,13 @@ def test_enable_extension_without_env_var(self):
291288
292289 self .assertEqual (b'"true"' , r .content )
293290
291+ def assertAround (self , number , target ):
292+ # Emulating arm64 on x86 causes the invoke to take longer
293+ delay_arm64 = 500
294+ actual_target = target if self .ARCH != 'arm64' else target - delay_arm64
295+
296+ self .assertLess (number , actual_target + 1000 )
297+ self .assertGreater (number , actual_target - 1000 )
298+
294299if __name__ == "__main__" :
295300 main ()
0 commit comments