forked from kevincox/appengine-sequential-ids
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_sequential.py
39 lines (32 loc) · 865 Bytes
/
test_sequential.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
#! /usr/bin/python
import random
import logging
import increment
increment.logger.setLevel(logging.DEBUG)
#for e in db.GqlQuery("SELECT * FROM IncrementCounter"):
# e.delete()
def run(rounds=1000, name="test", chunk=7, **kwargs):
inc = increment.Increment(name, chunk, min=0, **kwargs)
results = set()
def trytoadd(ids):
for id in ids:
if id in results:
print "ERROR: Got id twice", id
results.add(id)
for _ in xrange(rounds):
r = random.randint(0,2)
if r == 0:
res = inc.next(random.randint(0,9))
print "Used next() to get", res
trytoadd(res)
if r == 1:
l, h = inc.reserve(random.randint(0,9))
print "Used reserve() to get", l, h
trytoadd(range(l,h))
if r == 2:
res = inc.one()
print "Used one() to get", res
trytoadd([res])
for id in xrange(max(results)):
if id not in results:
print "Missing", id