@@ -315,6 +315,10 @@ func (suite *lruPolicyTestSuite) verifyPolicy(expectedPolicy, actualPolicy *lruP
315315 suite .assert .Same (actualPolicy .lastMarker , actual )
316316 default :
317317 suite .assert .Equal (expected .name , actual .name )
318+ objName := expected .name [len (suite .policy .tmpPath )+ 1 :]
319+ _ , expectedPending := expectedPolicy .pendingOps .Load (objName )
320+ _ , actualPending := actualPolicy .pendingOps .Load (objName )
321+ suite .assert .Equal (expectedPending , actualPending )
318322 }
319323 suite .assert .NotNil (actual , "actual list is shorter than expected" )
320324 suite .assert .NotNil (expected , "actual list is longer than expected" )
@@ -337,6 +341,32 @@ func (suite *lruPolicyTestSuite) TestCreateSnapshotEmpty() {
337341 suite .verifyPolicy (originalPolicy , suite .policy )
338342}
339343
344+ func (suite * lruPolicyTestSuite ) TestCreateSnapshot () {
345+ defer suite .cleanupTest ()
346+ // setup
347+ numFiles := 5
348+ pathPrefix := filepath .Join (cache_path , "temp" )
349+ for i := 1 ; i <= numFiles ; i ++ {
350+ suite .policy .CacheValid (pathPrefix + fmt .Sprint (i ))
351+ if i > 3 {
352+ suite .policy .pendingOps .Store ("temp" + fmt .Sprint (i ), struct {}{})
353+ }
354+ }
355+ originalPolicy := suite .policy
356+ // test
357+ snapshot := suite .policy .createSnapshot ()
358+ suite .cleanupTest ()
359+ suite .setupTestHelper (originalPolicy .cachePolicyConfig )
360+ suite .policy .loadSnapshot (snapshot )
361+ // assert
362+ suite .assert .NotNil (snapshot )
363+ suite .assert .Len (snapshot .NodeList , numFiles )
364+ for i , v := range snapshot .NodeList {
365+ suite .assert .Equal (pathPrefix + fmt .Sprint (numFiles - i ), filepath .Join (cache_path , v ))
366+ }
367+ suite .verifyPolicy (originalPolicy , suite .policy )
368+ }
369+
340370func (suite * lruPolicyTestSuite ) TestCreateSnapshotWithTrailingMarkers () {
341371 defer suite .cleanupTest ()
342372 // setup
@@ -481,6 +511,7 @@ func (suite *lruPolicyTestSuite) TestSnapshotSerialization() {
481511 NodeList : []string {"a" , "b" , "c" },
482512 CurrMarkerPosition : 1 ,
483513 LastMarkerPosition : 2 ,
514+ SyncPendingFlags : []bool {true , false , false },
484515 }
485516 // test
486517 err := snapshot .writeToFile (cache_path )
@@ -494,12 +525,11 @@ func (suite *lruPolicyTestSuite) TestSnapshotSerialization() {
494525func (suite * lruPolicyTestSuite ) TestNoEvictionIfInPendingOps () {
495526 defer suite .cleanupTest ()
496527
497- fileName := filepath .Join (cache_path , "scheduled_file" )
528+ name := "pending_file"
529+ fileName := filepath .Join (cache_path , name )
498530 suite .policy .CacheValid (fileName )
499531
500- fakeSchedule := & FileCache {}
501- fakeSchedule .pendingOps .Store (common .NormalizeObjectName ("scheduled_file" ), struct {}{})
502- suite .policy .schedule = fakeSchedule
532+ suite .policy .pendingOps .Store (name , struct {}{})
503533
504534 time .Sleep (2 * time .Second )
505535
@@ -509,20 +539,19 @@ func (suite *lruPolicyTestSuite) TestNoEvictionIfInPendingOps() {
509539func (suite * lruPolicyTestSuite ) TestEvictionRespectsPendingOps () {
510540 defer suite .cleanupTest ()
511541
542+ objNames := []string {"File1" , "file2" , "file3" , "file4" }
512543 fileNames := []string {
513- filepath .Join (cache_path , "file1" ),
514- filepath .Join (cache_path , "file2" ),
515- filepath .Join (cache_path , "file3" ),
516- filepath .Join (cache_path , "file4" ),
544+ filepath .Join (cache_path , objNames [ 0 ] ),
545+ filepath .Join (cache_path , objNames [ 1 ] ),
546+ filepath .Join (cache_path , objNames [ 2 ] ),
547+ filepath .Join (cache_path , objNames [ 3 ] ),
517548 }
518549 for _ , name := range fileNames {
519550 suite .policy .CacheValid (name )
520551 }
521552
522- fakeSchedule := & FileCache {}
523- fakeSchedule .pendingOps .Store (common .NormalizeObjectName ("file2" ), struct {}{})
524- fakeSchedule .pendingOps .Store (common .NormalizeObjectName ("file4" ), struct {}{})
525- suite .policy .schedule = fakeSchedule
553+ suite .policy .pendingOps .Store (objNames [1 ], struct {}{})
554+ suite .policy .pendingOps .Store (objNames [3 ], struct {}{})
526555
527556 time .Sleep (3 * time .Second )
528557
0 commit comments