-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·83 lines (60 loc) · 2.44 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/python
# Copyright 2013 Josh Pieper, [email protected]
import datetime
import unittest
import s3bdbk
class TestCase(unittest.TestCase):
def setUp(self):
pass
def sample_manifests(self, manifests, count):
# This is a random process. Take a bunch of samples and
# measure the histogram.
results = [0] * len(manifests)
for i in range(count):
this_result = s3bdbk.select_manifest_to_remove(manifests)
index = manifests.index(this_result)
results[index] += 1
return results
def test_select_manifest(self):
manifests = [
'manifest-20130101-162401-stuff',
'manifest-20130102-162401-stuff',
'manifest-20130103-162401-stuff',
'manifest-20130104-162401-stuff',
'manifest-20130105-162401-stuff',
'manifest-20130106-162401-stuff',
'manifest-20130107-162401-stuff',
'manifest-20130108-162401-stuff',
]
count = 5000
results = self.sample_manifests(manifests, count)
# Ensure that the first and last are never picked. Also
# ensure that the remainder are picked to be relatively evenly
# spaced.
self.assertEqual(results[0], 0)
self.assertEqual(results[-1], 0)
expected = count / (len(results) - 2)
for result in results[1:-1]:
self.assertTrue(abs(result - expected) < 0.8 * expected)
# If we we now remove one of the items, we expect its neighbor
# to be selected less frequently.
del manifests[4]
results = self.sample_manifests(manifests, count)
expected = count / (len(results) - 2)
self.assertTrue(results[4] < 0.8 * expected)
def test_select_manifest_over_time(self):
manifests = []
current = datetime.datetime(2013, 1, 1, 6, 0, 0)
for i in range(200):
manifests.append('manifest-%04d%02d%02d-060000-stuff' % (
current.year, current.month, current.day))
current = current + datetime.timedelta(1)
if len(manifests) > 25:
del manifests[
manifests.index(
s3bdbk.select_manifest_to_remove(manifests))]
# TODO: Construct some assertion that this is doing the right
# thing.
#print '\n'.join(manifests)
if __name__ == '__main__':
unittest.main()