@@ -223,7 +223,7 @@ def test_init_search_index_success(self) -> None:
223223 client = _make_mock_client ()
224224 backend = _make_backend (client )
225225 backend .init_search_index ()
226- client .create_search_index .assert_called_once ()
226+ assert client .create_search_index .call_count == 2
227227
228228 def test_init_search_index_already_exist (self ) -> None :
229229 client = _make_mock_client ()
@@ -237,8 +237,16 @@ def test_init_search_index_already_exist(self) -> None:
237237
238238 def test_init_search_index_other_error (self ) -> None :
239239 client = _make_mock_client ()
240- err = OTSServiceError (500 , "InternalError" , "internal error" )
241- client .create_search_index .side_effect = err
240+ call_count = 0
241+
242+ def _side_effect (* args : object , ** kwargs : object ) -> None :
243+ nonlocal call_count
244+ call_count += 1
245+ if call_count == 1 :
246+ return None
247+ raise OTSServiceError (500 , "InternalError" , "internal error" )
248+
249+ client .create_search_index .side_effect = _side_effect
242250
243251 backend = _make_backend (client )
244252 with pytest .raises (OTSServiceError ):
@@ -252,6 +260,7 @@ def test_table_prefix(self) -> None:
252260 assert backend ._state_table == "myprefix_state"
253261 assert backend ._app_state_table == "myprefix_app_state"
254262 assert backend ._user_state_table == "myprefix_user_state"
263+ assert backend ._state_search_index == "myprefix_state_search_index"
255264
256265
257266# ---------------------------------------------------------------------------
@@ -1225,6 +1234,7 @@ async def test_init_tables_already_exist(self) -> None:
12251234 async_client = MagicMock ()
12261235 err = OTSServiceError (409 , "OTSObjectAlreadyExist" , "already exist" )
12271236 async_client .create_table = AsyncMock (side_effect = err )
1237+ async_client .create_search_index = AsyncMock (side_effect = err )
12281238 backend = _make_async_backend (async_client )
12291239 await backend .init_tables_async ()
12301240
@@ -1233,6 +1243,7 @@ async def test_init_tables_other_error(self) -> None:
12331243 async_client = MagicMock ()
12341244 err = OTSServiceError (500 , "InternalError" , "error" )
12351245 async_client .create_table = AsyncMock (side_effect = err )
1246+ async_client .create_search_index = AsyncMock (side_effect = err )
12361247 backend = _make_async_backend (async_client )
12371248 with pytest .raises (OTSServiceError ):
12381249 await backend .init_tables_async ()
@@ -1253,7 +1264,7 @@ async def test_init_state_tables(self) -> None:
12531264 async def test_init_search_index (self ) -> None :
12541265 backend = _make_async_backend ()
12551266 await backend .init_search_index_async ()
1256- backend ._async_client .create_search_index .assert_called_once ()
1267+ assert backend ._async_client .create_search_index .call_count == 2
12571268
12581269 @pytest .mark .asyncio
12591270 async def test_init_search_index_already_exist (self ) -> None :
@@ -1268,8 +1279,16 @@ async def test_init_search_index_already_exist(self) -> None:
12681279 async def test_init_search_index_other_error (self ) -> None :
12691280 async_client = MagicMock ()
12701281 async_client .create_table = AsyncMock ()
1271- err = OTSServiceError (500 , "InternalError" , "error" )
1272- async_client .create_search_index = AsyncMock (side_effect = err )
1282+ call_count = 0
1283+
1284+ async def _side_effect (* args : object , ** kwargs : object ) -> None :
1285+ nonlocal call_count
1286+ call_count += 1
1287+ if call_count == 1 :
1288+ return None
1289+ raise OTSServiceError (500 , "InternalError" , "error" )
1290+
1291+ async_client .create_search_index = AsyncMock (side_effect = _side_effect )
12731292 backend = _make_async_backend (async_client )
12741293 with pytest .raises (OTSServiceError ):
12751294 await backend .init_search_index_async ()
0 commit comments