Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Bug 510957 - Switch from httplib2 to httplib for sending reports
Browse files Browse the repository at this point in the history
  • Loading branch information
whimboo committed May 30, 2010
1 parent dfe1ef0 commit 6a1c872
Showing 1 changed file with 38 additions and 12 deletions.
50 changes: 38 additions & 12 deletions mozmill/__init__.py
Expand Up @@ -37,14 +37,17 @@
#
# ***** END LICENSE BLOCK *****

import os
import sys
import copy
import socket
from datetime import datetime, timedelta
import httplib
import imp
import traceback
import os
import socket
import sys
import threading
from datetime import datetime, timedelta
import traceback
import urllib
import urlparse

try:
import json
Expand Down Expand Up @@ -81,6 +84,7 @@ def resetTimer(self):
self.doomsdayTimer = threading.Timer(1800, self.stopfunction)
self.doomsdayTimer.start()


class LoggerListener(object):
cases = {
'mozmill.pass': lambda obj: logger.debug('Test Pass: '+repr(obj)),
Expand All @@ -99,9 +103,11 @@ def __call__(self, eName, obj):
self.cases[eName] = self.default(eName)
self.cases[eName](obj)


class TestsFailedException(Exception):
pass


class MozMill(object):

def __init__(self, runner_class=mozrunner.FirefoxRunner,
Expand Down Expand Up @@ -185,6 +191,8 @@ def run_tests(self, test, report=False, sleeptime = 4):
# Reset our Zombie Because we are still active
#self.zombieDetector.resetTimer()

self.report_document = None

frame = jsbridge.JSObject(self.bridge,
"Components.utils.import('resource://mozmill/modules/frame.js')")
sleep(sleeptime)
Expand All @@ -202,7 +210,7 @@ def run_tests(self, test, report=False, sleeptime = 4):

if report:
results = self.get_report(test, starttime, endtime)
self.send_report(results, report)
self.report_document = self.send_report(results, report)

# Give a second for any callbacks to finish.
sleep(1)
Expand Down Expand Up @@ -269,12 +277,28 @@ def get_report(self, test, starttime, endtime):
return results

def send_report(self, results, report_url):
""" Send a report of the results to a CouchdB instance. """

try:
import httplib2
http = httplib2.Http()
response, content = http.request(report_url, 'POST', body=json.dumps(results))
except:
print "Sending results to '%s' failed." % report_url
# Parse URL fragments and send data
url_fragments = urlparse.urlparse(report_url)
connection = httplib.HTTPConnection(url_fragments.netloc)
connection.request("POST", url_fragments.path, json.dumps(results))

# Get response which contains the id of the new document
response = connection.getresponse()
data = json.loads(response.read())
connection.close()

# Check if the report has been created
if not data['ok']:
print "Creating report document failed (%s)" % data

# Print document location to the console and return
print "Report document created at '%s%s'" % (report_url, data['id'])
return data
except Exception, e:
print "Sending results to '%s' failed (%s)." % (report_url, e)

def stop(self, timeout=10):
sleep(1)
Expand Down Expand Up @@ -430,6 +454,8 @@ def run_tests(self, test_dir, report=False, sleeptime=4):
# Zombie Counter Reset
#self.zombieDetector.resetTimer()

self.report_document = None

test_dirs = [d for d in os.listdir(os.path.abspath(os.path.expanduser(test_dir)))
if d.startswith('test') and os.path.isdir(os.path.join(test_dir, d))]

Expand All @@ -454,7 +480,7 @@ def stop(self):

if report:
results = self.get_report(test_dir, starttime, endtime)
self.send_report(results, report)
self.report_document = self.send_report(results, report)

# Set to None to avoid calling .stop
self.runner = None
Expand Down

0 comments on commit 6a1c872

Please sign in to comment.