1
+ import time
2
+
1
3
from mock import patch , ANY , call
2
4
3
5
from arctic .auth import Credential
@@ -12,8 +14,7 @@ def test_prune_versions_symbol(mongo_host, library, library_name):
12
14
patch ('pymongo.database.Database.authenticate' , return_value = True ):
13
15
14
16
run_as_main (mpv .main , '--host' , mongo_host , '--library' , library_name , '--symbols' , 'sym1,sym2' )
15
- prune_versions .assert_has_calls ([call (ANY , 'sym1' , 10 ),
16
- call (ANY , 'sym2' , 10 ), ])
17
+ prune_versions .assert_has_calls ([call (ANY , ['sym1' , 'sym2' ], 10 )])
17
18
18
19
19
20
def test_prune_versions_full (mongo_host , library , library_name ):
@@ -37,3 +38,40 @@ def test_prune_versions_full(mongo_host, library, library_name):
37
38
library .delete_snapshot ('snap1' )
38
39
run_as_main (mpv .main , '--host' , mongo_host , '--library' , library_name , '--keep-mins' , 0 )
39
40
assert [x ['version' ] for x in library .list_versions ('symbol' )] == [3 ]
41
+
42
+
43
+ def test_keep_recent_snapshots (library ):
44
+ library .write ("cherry" , "blob" )
45
+ half_a_day_ago = time .time () - (3600 * 12. )
46
+ with patch ('time.time' , return_value = half_a_day_ago ):
47
+ library .snapshot ("snappy" )
48
+ library ._snapshots .delete_one ({"name" : "snappy" })
49
+
50
+ mpv .prune_versions (library , ["cherry" ], 10 )
51
+
52
+ assert len (library ._versions .find_one ({"symbol" : "cherry" }).get ("parent" , [])) == 1
53
+
54
+
55
+ def test_fix_broken_snapshot_references (library ):
56
+ library .write ("cherry" , "blob" )
57
+ one_day_ago = time .time () - (3600 * 24. ) - 10 # make sure we are a few seconds before 24 hours
58
+ with patch ('time.time' , return_value = one_day_ago ):
59
+ library .snapshot ("snappy" )
60
+ library ._snapshots .delete_one ({"name" : "snappy" })
61
+
62
+ mpv .prune_versions (library , ["cherry" ], 10 )
63
+
64
+ assert library ._versions .find_one ({"symbol" : "cherry" }).get ("parent" , []) == []
65
+
66
+
67
+ def test_keep_only_one_version (library ):
68
+ library .write ("cherry" , "blob" )
69
+ library .write ("cherry" , "blob" )
70
+ one_day_ago = time .time () - (3600 * 24. ) - 10 # make sure we are a few seconds before 24 hours
71
+ with patch ('time.time' , return_value = one_day_ago ):
72
+ library .snapshot ("snappy" )
73
+ library ._snapshots .delete_one ({"name" : "snappy" })
74
+
75
+ mpv .prune_versions (library , ["cherry" ], 0 )
76
+
77
+ assert len (list (library ._versions .find ({"symbol" : "cherry" }))) == 1
0 commit comments