@@ -3443,31 +3443,30 @@ public async void TestDocumentLoadWithDB_Issue352(string endpointId)
34433443 IDatabase db = GetCleanDatabase ( endpointId ) ;
34443444 var ft = db . FT ( ) ;
34453445
3446- Schema sc = new Schema ( ) . AddTextField ( "first " , 1.0 ) . AddTextField ( "last " , 1.0 ) . AddNumericField ( "age " ) ;
3446+ Schema sc = new Schema ( ) . AddTextField ( "firstText " , 1.0 ) . AddTextField ( "lastText " , 1.0 ) . AddNumericField ( "ageNumeric " ) ;
34473447 Assert . True ( ft . Create ( index , FTCreateParams . CreateParams ( ) , sc ) ) ;
34483448
34493449 Document droppedDocument = null ;
34503450 int numberOfAttempts = 0 ;
3451-
34523451 do
34533452 {
34543453 // try until succesfully create the key and set the TTL
34553454 bool ttlRefreshed = false ;
3456- Int32 completed = 0 ;
3457-
34583455 do
34593456 {
3460- db . HashSet ( "student:1111 " , new HashEntry [ ] { new ( "first " , "Joe" ) , new ( "last " , "Dod" ) , new ( "age " , 18 ) } ) ;
3461- ttlRefreshed = db . KeyExpire ( "student:1111 " , TimeSpan . FromMilliseconds ( 500 ) ) ;
3457+ db . HashSet ( "student:22222 " , new HashEntry [ ] { new ( "firstText " , "Joe" ) , new ( "lastText " , "Dod" ) , new ( "ageNumeric " , 18 ) } ) ;
3458+ ttlRefreshed = db . KeyExpire ( "student:22222 " , TimeSpan . FromMilliseconds ( 500 ) ) ;
34623459 } while ( ! ttlRefreshed ) ;
34633460
3464- Boolean cancelled = false ;
3461+ Int32 completed = 0 ;
3462+
34653463 Action checker = ( ) =>
34663464 {
3467- for ( int i = 0 ; i < 100000 && ! cancelled ; i ++ )
3465+ for ( int i = 0 ; i < 1000000 ; i ++ )
34683466 {
34693467 SearchResult result = ft . Search ( index , new Query ( ) ) ;
34703468 List < Document > docs = result . Documents ;
3469+
34713470 // check if doc is already dropped before search and load;
34723471 // if yes then its already late and we missed the window that
34733472 // doc would show up in search result with no fields
@@ -3477,30 +3476,28 @@ public async void TestDocumentLoadWithDB_Issue352(string endpointId)
34773476 break ;
34783477 }
34793478 // if we get a document with no fields then we know that the key
3480- // expired while the query is running, and we are able to catch the state
3481- // so we can break the loop
3479+ // is going to be expired while the query is running, and we are able to catch the state
3480+ // but key itself might not be expired yet
34823481 else if ( docs [ 0 ] . GetProperties ( ) . Count ( ) == 0 )
34833482 {
34843483 droppedDocument = docs [ 0 ] ;
3485- Interlocked . Increment ( ref completed ) ;
3486- break ;
34873484 }
34883485 }
34893486 } ;
34903487
34913488 List < Task > tasks = new List < Task > ( ) ;
34923489 // try with 3 different tasks simultaneously to increase the chance of hitting it
3493- for ( int i = 0 ; i < 3 ; i ++ )
3494- {
3495- tasks . Add ( Task . Run ( checker ) ) ;
3496- }
3490+ for ( int i = 0 ; i < 3 ; i ++ ) { tasks . Add ( Task . Run ( checker ) ) ; }
34973491 Task checkTask = Task . WhenAll ( tasks ) ;
3498- await Task . WhenAny ( checkTask , Task . Delay ( 1500 ) ) ;
3492+ await Task . WhenAny ( checkTask , Task . Delay ( 1000 ) ) ;
3493+ var keyTtl = db . KeyTimeToLive ( "student:22222" ) ;
3494+ Assert . Equal ( 0 , keyTtl . HasValue ? keyTtl . Value . Milliseconds : 0 ) ;
34993495 Assert . Equal ( 3 , completed ) ;
3500- cancelled = true ;
35013496 } while ( droppedDocument == null && numberOfAttempts ++ < 5 ) ;
3502- // we wont do an actual assert here since
3497+ // we won't do an actual assert here since
35033498 // it is not guaranteed that window stays open wide enough to catch it.
3504- // instead we attempt 5 times
3499+ // instead we attempt 5 times.
3500+ // Without fix for Issue352, document load in this case fails %100 with my local test runs,, and %100 success with fixed version.
3501+ // The results in pipeline should be the same.
35053502 }
35063503}
0 commit comments