@@ -58,7 +58,7 @@ public async Task Indexes_should_be_reset_on_setup()
5858
5959 await DatabaseSetup . CreateIndexes ( configuration . DocumentStore , true , CancellationToken . None ) ;
6060
61- WaitForIndexDefinitionUpdate ( indexWithCustomConfigStats ) ;
61+ await WaitForIndexDefinitionUpdate ( indexWithCustomConfigStats ) ;
6262
6363 var indexAfterResetStats = await configuration . DocumentStore . Maintenance . SendAsync ( new GetIndexStatisticsOperation ( index . IndexName ) ) ;
6464
@@ -101,30 +101,34 @@ public async Task Indexes_should_not_be_reset_on_setup_when_locked_as_error()
101101 Assert . ThrowsAsync < IndexCreationException > ( async ( ) => await DatabaseSetup . CreateIndexes ( configuration . DocumentStore , true , CancellationToken . None ) ) ;
102102 }
103103
104- async Task < IndexStats > UpdateIndex ( IAbstractIndexCreationTask index )
104+ async Task < IndexStats > UpdateIndex ( IAbstractIndexCreationTask index , CancellationToken cancellationToken = default )
105105 {
106- var statsBefore = await configuration . DocumentStore . Maintenance . SendAsync ( new GetIndexStatisticsOperation ( index . IndexName ) ) ;
106+ var statsBefore = await configuration . DocumentStore . Maintenance . SendAsync ( new GetIndexStatisticsOperation ( index . IndexName ) , cancellationToken ) ;
107107
108- await IndexCreation . CreateIndexesAsync ( [ index ] , configuration . DocumentStore ) ;
108+ await IndexCreation . CreateIndexesAsync ( [ index ] , configuration . DocumentStore , null , null , cancellationToken ) ;
109109
110- WaitForIndexDefinitionUpdate ( statsBefore ) ;
111-
112- return await configuration . DocumentStore . Maintenance . SendAsync ( new GetIndexStatisticsOperation ( index . IndexName ) ) ;
110+ return await WaitForIndexDefinitionUpdate ( statsBefore , cancellationToken ) ;
113111 }
114112
115- void WaitForIndexDefinitionUpdate ( IndexStats indexStats )
113+ async Task < IndexStats > WaitForIndexDefinitionUpdate ( IndexStats oldStats , CancellationToken cancellationToken = default )
116114 {
117- Assert . That ( SpinWait . SpinUntil ( ( ) =>
115+ while ( true )
118116 {
119117 try
120118 {
121- return configuration . DocumentStore . Maintenance . Send ( new GetIndexStatisticsOperation ( indexStats . Name ) ) . CreatedTimestamp > indexStats . CreatedTimestamp ;
119+ var newStats = await configuration . DocumentStore . Maintenance . SendAsync ( new GetIndexStatisticsOperation ( oldStats . Name ) , cancellationToken ) ;
120+
121+ if ( newStats . CreatedTimestamp > oldStats . CreatedTimestamp )
122+ {
123+ return newStats ;
124+ }
122125 }
123126 catch ( OperationCanceledException )
124127 {
125128 // keep going since we can get this if we query right when the update happens
126- return false ;
127129 }
128- } , TimeSpan . FromSeconds ( 10 ) ) , Is . True ) ;
130+
131+ await Task . Delay ( TimeSpan . FromMilliseconds ( 100 ) , cancellationToken ) ;
132+ }
129133 }
130134}
0 commit comments