@@ -173,9 +173,8 @@ def test_context_get_remaining_time_in_three_seconds(self):
173173 with self .create_container (params , image ):
174174 r = self .invoke_function ()
175175
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 )
179178
180179
181180 def test_context_get_remaining_time_in_ten_seconds (self ):
@@ -186,9 +185,8 @@ def test_context_get_remaining_time_in_ten_seconds(self):
186185 with self .create_container (params , image ):
187186 r = self .invoke_function ()
188187
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 )
192190
193191
194192 def test_context_get_remaining_time_in_default_deadline (self ):
@@ -199,9 +197,8 @@ def test_context_get_remaining_time_in_default_deadline(self):
199197 with self .create_container (params , image ):
200198 r = self .invoke_function ()
201199
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 )
205202
206203
207204 def test_invoke_with_pre_runtime_api_runtime (self ):
@@ -256,6 +253,13 @@ def test_custom_client_context(self):
256253 self .assertEqual ("bar" , content ["foo" ])
257254 self .assertEqual (123 , content ["baz" ])
258255
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 )
259263
260264if __name__ == "__main__" :
261265 main ()
0 commit comments