@@ -3443,31 +3443,30 @@ public async void TestDocumentLoadWithDB_Issue352(string endpointId)
3443
3443
IDatabase db = GetCleanDatabase ( endpointId ) ;
3444
3444
var ft = db . FT ( ) ;
3445
3445
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 " ) ;
3447
3447
Assert . True ( ft . Create ( index , FTCreateParams . CreateParams ( ) , sc ) ) ;
3448
3448
3449
3449
Document droppedDocument = null ;
3450
3450
int numberOfAttempts = 0 ;
3451
-
3452
3451
do
3453
3452
{
3454
3453
// try until succesfully create the key and set the TTL
3455
3454
bool ttlRefreshed = false ;
3456
- Int32 completed = 0 ;
3457
-
3458
3455
do
3459
3456
{
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 ) ) ;
3462
3459
} while ( ! ttlRefreshed ) ;
3463
3460
3464
- Boolean cancelled = false ;
3461
+ Int32 completed = 0 ;
3462
+
3465
3463
Action checker = ( ) =>
3466
3464
{
3467
- for ( int i = 0 ; i < 100000 && ! cancelled ; i ++ )
3465
+ for ( int i = 0 ; i < 1000000 ; i ++ )
3468
3466
{
3469
3467
SearchResult result = ft . Search ( index , new Query ( ) ) ;
3470
3468
List < Document > docs = result . Documents ;
3469
+
3471
3470
// check if doc is already dropped before search and load;
3472
3471
// if yes then its already late and we missed the window that
3473
3472
// doc would show up in search result with no fields
@@ -3477,30 +3476,28 @@ public async void TestDocumentLoadWithDB_Issue352(string endpointId)
3477
3476
break ;
3478
3477
}
3479
3478
// 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
3482
3481
else if ( docs [ 0 ] . GetProperties ( ) . Count ( ) == 0 )
3483
3482
{
3484
3483
droppedDocument = docs [ 0 ] ;
3485
- Interlocked . Increment ( ref completed ) ;
3486
- break ;
3487
3484
}
3488
3485
}
3489
3486
} ;
3490
3487
3491
3488
List < Task > tasks = new List < Task > ( ) ;
3492
3489
// 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 ) ) ; }
3497
3491
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 ) ;
3499
3495
Assert . Equal ( 3 , completed ) ;
3500
- cancelled = true ;
3501
3496
} while ( droppedDocument == null && numberOfAttempts ++ < 5 ) ;
3502
- // we wont do an actual assert here since
3497
+ // we won't do an actual assert here since
3503
3498
// 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.
3505
3502
}
3506
3503
}
0 commit comments