1- // Copyright (C) 2003- 2016 Xtensive LLC.
2- // All rights reserved .
3- // For conditions of distribution and use, see license .
1+ // Copyright (C) 2016-2025 Xtensive LLC.
2+ // This code is distributed under MIT license terms .
3+ // See the License.txt file in the project root for more information .
44// Created by: Alexey Kulakov
55// Created: 2016.12.09
66
77using System ;
8+ using System . Data . Common ;
89using System . Linq ;
910using System . Threading ;
1011using NUnit . Framework ;
1112using Xtensive . Core ;
1213using Xtensive . Orm . Providers ;
14+ using Xtensive . Orm . Services ;
1315using Xtensive . Orm . Tests . ObjectModel ;
1416using Xtensive . Orm . Tests . ObjectModel . ChinookDO ;
1517
@@ -25,8 +27,31 @@ protected override void CheckRequirements()
2527 protected override Domain BuildDomain ( Xtensive . Orm . Configuration . DomainConfiguration configuration )
2628 {
2729 var domain = base . BuildDomain ( configuration ) ;
28- Thread . Sleep ( TimeSpan . FromSeconds ( 6 ) ) ;
30+ if ( StorageProviderInfo . Instance . Provider == StorageProvider . SqlServer ) {
31+ using ( var session = domain . OpenSession ( ) )
32+ using ( var tx = session . OpenTransaction ( ) ) {
33+ var sqlAccessor = session . Services . Get < DirectSqlAccessor > ( ) ;
34+ var timeout = DateTime . UtcNow . AddSeconds ( 20 ) ;
35+ while ( ! CheckFtIndexesPopulated ( sqlAccessor . CreateCommand ( ) ) && DateTime . UtcNow < timeout ) {
36+ Console . WriteLine ( "There are unpopulated FT indexes. Waiting" ) ;
37+ Thread . Sleep ( TimeSpan . FromSeconds ( 2 ) ) ;
38+ }
39+ return domain ;
40+ }
41+ }
42+ else {
43+ Thread . Sleep ( TimeSpan . FromSeconds ( 6 ) ) ;
44+ }
2945 return domain ;
46+
47+
48+ static bool CheckFtIndexesPopulated ( DbCommand sqlCommand )
49+ {
50+ using ( sqlCommand ) {
51+ sqlCommand . CommandText = $ "SELECT COUNT(*) FROM [{ WellKnownDatabases . MultiDatabase . MainDb } ].sys.fulltext_indexes WHERE has_crawl_completed=0";
52+ return ( ( int ) sqlCommand . ExecuteScalar ( ) ) == 0 ;
53+ }
54+ }
3055 }
3156
3257 [ Test ]
0 commit comments