mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-04-21 16:16:28 -04:00
Merge branch 'choose-warcprox' into qa
* choose-warcprox: test and fix choose_warcprox
This commit is contained in:
commit
78f079154a
@ -133,9 +133,10 @@ class BrozzlerWorker:
|
||||
warcproxes = self._service_registry.available_services('warcprox')
|
||||
if not warcproxes:
|
||||
return None
|
||||
active_sites = self._frontier.rr.table('sites').between(
|
||||
reql = self._frontier.rr.table('sites').between(
|
||||
['ACTIVE', r.minval], ['ACTIVE', r.maxval],
|
||||
index='sites_last_disclaimed').run()
|
||||
index='sites_last_disclaimed')
|
||||
active_sites = list(reql.run())
|
||||
for warcprox in warcproxes:
|
||||
address = '%s:%s' % (warcprox['host'], warcprox['port'])
|
||||
warcprox['assigned_sites'] = len([
|
||||
|
@ -855,3 +855,71 @@ def test_claim_site():
|
||||
# clean up
|
||||
rr.table('sites').get(claimed_site.id).delete().run()
|
||||
|
||||
def test_choose_warcprox():
|
||||
rr = doublethink.Rethinker('localhost', db='ignoreme')
|
||||
svcreg = doublethink.ServiceRegistry(rr)
|
||||
frontier = brozzler.RethinkDbFrontier(rr)
|
||||
# clean slate
|
||||
rr.table('sites').delete().run()
|
||||
rr.table('services').delete().run()
|
||||
worker = brozzler.BrozzlerWorker(frontier, svcreg)
|
||||
assert worker._choose_warcprox() is None
|
||||
|
||||
rr.table('services').insert({
|
||||
'role': 'warcprox',
|
||||
'first_heartbeat': doublethink.utcnow(),
|
||||
'last_heartbeat': doublethink.utcnow(),
|
||||
'host': 'host1', 'port': 8000,
|
||||
'load': 0, 'ttl': 60}).run()
|
||||
rr.table('services').insert({
|
||||
'role': 'warcprox',
|
||||
'first_heartbeat': doublethink.utcnow(),
|
||||
'last_heartbeat': doublethink.utcnow(),
|
||||
'host': 'host2', 'port': 8000,
|
||||
'load': 0, 'ttl': 60}).run()
|
||||
rr.table('services').insert({
|
||||
'role': 'warcprox',
|
||||
'first_heartbeat': doublethink.utcnow(),
|
||||
'last_heartbeat': doublethink.utcnow(),
|
||||
'host': 'host2', 'port': 8001,
|
||||
'load': 0, 'ttl': 60}).run()
|
||||
rr.table('services').insert({
|
||||
'role': 'warcprox',
|
||||
'first_heartbeat': doublethink.utcnow(),
|
||||
'last_heartbeat': doublethink.utcnow(),
|
||||
'host': 'host3', 'port': 8000,
|
||||
'load': 0, 'ttl': 60}).run()
|
||||
rr.table('services').insert({
|
||||
'role': 'warcprox',
|
||||
'first_heartbeat': doublethink.utcnow(),
|
||||
'last_heartbeat': doublethink.utcnow(),
|
||||
'host': 'host4', 'port': 8000,
|
||||
'load': 1, 'ttl': 60}).run()
|
||||
|
||||
rr.table('sites').insert({
|
||||
'proxy': 'host1:8000', 'status': 'ACTIVE',
|
||||
'last_disclaimed': doublethink.utcnow()}).run()
|
||||
rr.table('sites').insert({
|
||||
'proxy': 'host1:8000', 'status': 'ACTIVE',
|
||||
'last_disclaimed': doublethink.utcnow()}).run()
|
||||
rr.table('sites').insert({
|
||||
'proxy': 'host2:8000', 'status': 'ACTIVE',
|
||||
'last_disclaimed': doublethink.utcnow()}).run()
|
||||
rr.table('sites').insert({
|
||||
'proxy': 'host2:8001', 'status': 'ACTIVE',
|
||||
'last_disclaimed': doublethink.utcnow()}).run()
|
||||
|
||||
instance = worker._choose_warcprox()
|
||||
assert instance['host'] == 'host3'
|
||||
assert instance['port'] == 8000
|
||||
rr.table('sites').insert({
|
||||
'proxy': 'host3:8000', 'status': 'ACTIVE',
|
||||
'last_disclaimed': doublethink.utcnow()}).run()
|
||||
|
||||
instance = worker._choose_warcprox()
|
||||
assert instance['host'] == 'host4'
|
||||
assert instance['port'] == 8000
|
||||
|
||||
# clean up
|
||||
rr.table('sites').delete().run()
|
||||
rr.table('services').delete().run()
|
||||
|
Loading…
x
Reference in New Issue
Block a user