Commit 701074eb authored by Jelte Jansen's avatar Jelte Jansen
Browse files

[1290] generalized a few steps so we can use multiple processes

parent e0094385
from lettuce import *
import subprocess
@world.absorb
def shutdown_server():
if world.bind10 is not None:
world.bind10.terminate()
world.bind10.wait()
world.bind10 = None
def check_lines(output, lines):
for line in lines:
if output.find(line) != -1:
return line
@world.absorb
def wait_for_output_lines(lines, examine_past = True):
assert world.bind10 is not None
def wait_for_output_lines_stdout(process_name, lines, examine_past = True):
assert process_name in world.processes
if examine_past:
for output in world.processes_stdout[process_name]:
for line in lines:
if output.find(line) != -1:
return line
found = False
while not found:
output = world.processes[process_name].stdout.readline()
# store any line, for examine_skipped
world.processes_stdout[process_name].append(output)
for line in lines:
if output.find(line) != -1:
return line
@world.absorb
def wait_for_output_lines_stderr(process_name, lines, examine_past = True):
assert process_name in world.processes
if examine_past:
for output in world.bind10_output:
for output in world.processes_stderr[process_name]:
for line in lines:
if output.find(line) != -1:
return line
found = False
while not found:
output = world.bind10.stderr.readline()
output = world.processes[process_name].stderr.readline()
# store any line, for examine_skipped
world.bind10_output.append(output)
world.processes_stderr[process_name].append(output)
for line in lines:
if output.find(line) != -1:
return line
@step('start bind10(?: with configuration ([\w.]+))?')
def start_bind10(step, config_file):
@step('start bind10(?: with configuration ([\w.]+))?(?: as (\w+))?')
def start_bind10(step, config_file, process_name):
args = [ 'bind10', '-v' ]
if config_file is not None:
args.append('-p')
......@@ -39,32 +49,35 @@ def start_bind10(step, config_file):
args.append('-c')
args.append(config_file)
args.append('--cmdctl-port=47805')
if process_name is None:
process_name = "bind10"
world.bind10 = subprocess.Popen(args, 1, None, subprocess.PIPE,
subprocess.PIPE, subprocess.PIPE)
assert process_name not in world.processes,\
"There already seems to be a process named " + process_name
world.processes[process_name] = subprocess.Popen(args, 1, None,
subprocess.PIPE,
subprocess.PIPE,
subprocess.PIPE)
world.processes_stdout[process_name] = []
world.processes_stderr[process_name] = []
# check output to know when startup has been completed
# TODO what to do on failure?
message = world.wait_for_output_lines(["BIND10_STARTUP_COMPLETE",
"BIND10_STARTUP_ERROR"])
message = world.wait_for_output_lines_stderr(process_name,
["BIND10_STARTUP_COMPLETE",
"BIND10_STARTUP_ERROR"])
assert message == "BIND10_STARTUP_COMPLETE"
@step('wait for bind10 auth to start')
def wait_for_auth(step):
world.wait_for_output_lines(['AUTH_SERVER_STARTED'])
@step('wait for bind10 auth (?:of (\w+) )?to start')
def wait_for_auth(step, process_name):
if process_name is None:
process_name = "bind10"
world.wait_for_output_lines_stderr(process_name, ['AUTH_SERVER_STARTED'])
@step('have bind10 running(?: with configuration ([\w.]+))?')
def have_bind10_running(step, config_file):
step.given('start bind10 with configuration ' + config_file)
step.given('wait for bind10 auth to start')
@step('wait for log message (\w+)')
def wait_for_message(step, message):
world.wait_for_output_lines([message], False)
@step('stop bind10')
def stop_the_server(step):
world.shutdown_server()
@step('set bind10 configuration (\S+) to (.*)')
def set_config_command(step, name, value):
args = ['bindctl', '-p', '47805']
......
......@@ -7,7 +7,7 @@ Feature: SQLite3 backend
Given I have no database
When I start bind10 with configuration no_db_file.config
Then wait for bind10 auth to start
Then stop bind10
Then stop process bind10
I should see a database file
Scenario: example.org queries
......@@ -63,13 +63,13 @@ Feature: SQLite3 backend
When I start bind10 with configuration example.org.config
Then wait for bind10 auth to start
Wait for log message CMDCTL_STARTED
Wait for bind10 stderr message CMDCTL_STARTED
A query for www.example.org should have rcode NOERROR
Wait for log message AUTH_SEND_NORMAL_RESPONSE
Wait for bind10 stderr message AUTH_SEND_NORMAL_RESPONSE
Then set bind10 configuration Auth/database_file to data/empty_db.sqlite3
And wait for log message DATASRC_SQLITE_OPEN
And wait for bind10 stderr message DATASRC_SQLITE_OPEN
A query for www.example.org should have rcode REFUSED
Wait for log message AUTH_SEND_NORMAL_RESPONSE
Wait for bind10 stderr message AUTH_SEND_NORMAL_RESPONSE
Then set bind10 configuration Auth/database_file to data/example.org.sqlite3
And wait for log message DATASRC_SQLITE_OPEN
And wait for bind10 stderr message DATASRC_SQLITE_OPEN
A query for www.example.org should have rcode NOERROR
#
# This file contains a number of common steps that are general and may be used
# By a lot of feature files.
#
from lettuce import *
import os
@step('stop process (\w+)')
def stop_a_named_process(step, process_name):
world.stop_process(process_name)
@step('wait for (\w+) stderr message (\w+)')
def wait_for_message(step, process_name, message):
world.wait_for_output_lines_stderr(process_name, [message], False)
@step('wait for (\w+) stdout message (\w+)')
def wait_for_message(step, process_name, message):
world.wait_for_output_lines_stdout(process_name, [message], False)
@step('Given I have no database')
def given_i_have_no_database(step):
if os.path.exists("test.db"):
......
......@@ -23,8 +23,9 @@ copylist = [
def initialize(feature):
# just make sure our cleanup won't fail if we never did
# run the bind10 instance
world.bind10 = None
world.bind10_output = []
world.processes = {}
world.processes_stdout = {}
world.processes_stderr = {}
world.last_query_result = None
# Some tests can modify the settings. If the tests fail half-way, or
......@@ -35,7 +36,17 @@ def initialize(feature):
@after.each_scenario
def cleanup(feature):
world.shutdown_server()
world.bind10_output = []
# Stop any running processes we may have had around
for name in world.processes:
world.processes[name].terminate()
world.processes[name].wait()
world.processes_stdout[name] = []
world.processes_stderr[name] = []
@world.absorb
def stop_process(process_name):
if process_name in world.processes:
p = world.processes[process_name]
p.terminate()
p.wait()
del world.processes[process_name]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment