From c864499a64391c50080c5f5a49fe2a9f508984ad Mon Sep 17 00:00:00 2001 From: Noah Levitt Date: Wed, 14 Sep 2016 17:06:49 -0700 Subject: [PATCH] starting to create a framework for testing --- setup.py | 2 +- tests/htdocs/file1.txt | 1 + tests/test_cluster.py | 88 ++++++++++++++++++++++++++++++++++++++++++ vagrant/run-tests.sh | 12 ++++++ 4 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 tests/htdocs/file1.txt create mode 100644 tests/test_cluster.py create mode 100755 vagrant/run-tests.sh diff --git a/setup.py b/setup.py index b900d15..083a52b 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ def find_package_data(package): setuptools.setup( name='brozzler', - version='1.1b6.dev80', + version='1.1b6.dev81', description='Distributed web crawling with browsers', url='https://github.com/internetarchive/brozzler', author='Noah Levitt', diff --git a/tests/htdocs/file1.txt b/tests/htdocs/file1.txt new file mode 100644 index 0000000..d4a2f1c --- /dev/null +++ b/tests/htdocs/file1.txt @@ -0,0 +1 @@ +I'm a plain text file. diff --git a/tests/test_cluster.py b/tests/test_cluster.py new file mode 100644 index 0000000..7f8033d --- /dev/null +++ b/tests/test_cluster.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python +''' +cluster-integration-tests.py - integration tests for a brozzler cluster, +expects brozzler, warcprox, pywb, rethinkdb and other dependencies to be +running already + +Copyright (C) 2016 Internet Archive + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +''' + +import pytest +import http.server +import threading +import urllib.request +import os +import socket +import rethinkstuff + +@pytest.fixture(scope='module') +def httpd(request): + # SimpleHTTPRequestHandler always uses CWD so we have to chdir + os.chdir(os.path.join(os.path.dirname(__file__), 'htdocs')) + + httpd = http.server.HTTPServer( + ('localhost', 0), http.server.SimpleHTTPRequestHandler) + httpd_thread = threading.Thread(name='httpd', target=httpd.serve_forever) + httpd_thread.start() + + def fin(): + httpd.shutdown() + httpd.server_close() + httpd_thread.join() + request.addfinalizer(fin) + + return httpd + +def test_httpd(httpd): + ''' + Tests that our http server is working as expected, and that two fetches + of the same url return the same payload, proving it can be used to test + deduplication. + ''' + payload1 = content2 = None + with urllib.request.urlopen( + 'http://localhost:%s/' % httpd.server_port) as response: + assert response.status == 200 + payload1 = response.read() + assert payload1 + + with urllib.request.urlopen( + 'http://localhost:%s/' % httpd.server_port) as response: + assert response.status == 200 + payload2 = response.read() + assert payload2 + + assert payload1 == payload2 + +def test_services_up(): + '''Check that the expected services are up and running.''' + # check that warcprox is listening + with socket.socket() as s: + # if the connect fails an exception is raised and the test fails + s.connect(('localhost', 8000)) + + ### # check that pywb is listening + ### with socket.socket() as s: + ### # if the connect fails an exception is raised and the test fails + ### s.connect(('localhost', 8880)) + + # check that rethinkdb is listening and looks sane + r = rethinkstuff.Rethinker(db='rethinkdb') # built-in db + tbls = r.table_list().run() + assert len(tbls) > 10 + +def test_brozzle_site(httpd): + pass + diff --git a/vagrant/run-tests.sh b/vagrant/run-tests.sh new file mode 100755 index 0000000..42cd6f9 --- /dev/null +++ b/vagrant/run-tests.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +echo service status: +vagrant ssh -- 'status warcprox ; + status Xvnc ; + status brozzler-worker ; + status brozzler-webconsole ; + status vnc-websock' +echo + +vagrant ssh -- 'source brozzler-ve34/bin/activate && pip install pytest' +vagrant ssh -- 'source brozzler-ve34/bin/activate && py.test -v -s /brozzler/tests'