Fix tests on 32bit and other curl version

pull/1/merge
Daniel Richman 2012-08-20 15:07:25 +00:00
rodzic 6ed70acd99
commit 4303572e07
10 zmienionych plików z 80 dodań i 43 usunięć

Wyświetl plik

@ -4,10 +4,15 @@
jsoncpp_cflags := $(shell pkg-config --cflags jsoncpp) jsoncpp_cflags := $(shell pkg-config --cflags jsoncpp)
jsoncpp_libs := $(shell pkg-config --libs jsoncpp) jsoncpp_libs := $(shell pkg-config --libs jsoncpp)
curl_cflags := $(shell pkg-config --cflags libcurl)
curl_libs := $(shell pkg-config --libs libcurl)
ssl_cflags := $(shell pkg-config --cflags openssl)
ssl_libs := $(shell pkg-config --libs openssl)
CFLAGS = -pthread -O2 -Wall -Werror -pedantic -Wno-long-long \ CFLAGS = -pthread -O2 -Wall -Werror -pedantic -Wno-long-long \
-Wno-variadic-macros -Isrc $(jsoncpp_cflags) -Wno-variadic-macros -Isrc \
upl_libs = -pthread $(jsoncpp_libs) -lcurl -lssl $(jsoncpp_cflags) $(curl_cflags) $(ssl_cflags)
upl_libs = -pthread $(jsoncpp_libs) $(curl_libs) $(ssl_libs)
ext_libs = $(jsoncpp_libs) ext_libs = $(jsoncpp_libs)
rfc_libs = $(jsoncpp_libs) rfc_libs = $(jsoncpp_libs)

Wyświetl plik

@ -134,7 +134,7 @@ void Database::save_doc(Json::Value &doc)
{ {
response = server.curl.put(doc_url, json_doc); response = server.curl.put(doc_url, json_doc);
} }
catch (EZ::HTTPResponse e) catch (EZ::HTTPResponse &e)
{ {
/* Catch HTTP 409 Resource Conflict */ /* Catch HTTP 409 Resource Conflict */

Wyświetl plik

@ -21,7 +21,7 @@ bool validate_rfc3339(const string &rfc3339)
{ {
rfc3339_to_timestamp(rfc3339); rfc3339_to_timestamp(rfc3339);
} }
catch (InvalidFormat e) catch (InvalidFormat &e)
{ {
return false; return false;
} }

Wyświetl plik

@ -66,7 +66,7 @@ void UKHASExtractor::push(char b, enum push_flags flags)
{ {
mgr->data(crude_parse()); mgr->data(crude_parse());
} }
catch (runtime_error e) catch (runtime_error &e)
{ {
mgr->status("UKHAS Extractor: crude parse failed: " + mgr->status("UKHAS Extractor: crude parse failed: " +
string(e.what())); string(e.what()));
@ -386,7 +386,7 @@ Json::Value UKHASExtractor::crude_parse()
attempt_settings(data, (*it), checksum_name, parts); attempt_settings(data, (*it), checksum_name, parts);
return data; return data;
} }
catch (runtime_error e) catch (runtime_error &e)
{ {
errors.push_back(e.what()); errors.push_back(e.what());
} }

Wyświetl plik

@ -175,7 +175,7 @@ string Uploader::payload_telemetry(const string &data,
database.save_doc(doc); database.save_doc(doc);
return doc_id; return doc_id;
} }
catch (CouchDB::Conflict e) catch (CouchDB::Conflict &e)
{ {
for (int attempts = 0; attempts < max_merge_attempts; attempts++) for (int attempts = 0; attempts < max_merge_attempts; attempts++)
{ {
@ -191,7 +191,7 @@ string Uploader::payload_telemetry(const string &data,
return doc_id; return doc_id;
} }
catch (CouchDB::Conflict e) catch (CouchDB::Conflict &e)
{ {
continue; continue;
} }

Wyświetl plik

@ -224,12 +224,12 @@ void *UploaderThread::run()
{ {
break; break;
} }
catch (runtime_error e) catch (runtime_error &e)
{ {
caught_exception(e); caught_exception(e);
continue; continue;
} }
catch (invalid_argument e) catch (invalid_argument &e)
{ {
caught_exception(e); caught_exception(e);
continue; continue;

Wyświetl plik

@ -33,7 +33,13 @@ class ProxyFunction(object):
args = [self.name] + list(args) args = [self.name] + list(args)
self.p.stdin.write(json.dumps(args)) self.p.stdin.write(json.dumps(args))
self.p.stdin.write("\n") self.p.stdin.write("\n")
return json.loads(self.p.stdout.readline()) response, thing = json.loads(self.p.stdout.readline())
if response == "return":
return thing
elif response == "time_t error":
raise ValueError("timestamp out of range for platform time_t")
else:
raise Exception(thing)
class ProxyFunctionModule(object): class ProxyFunctionModule(object):
@ -210,13 +216,20 @@ class TestTimestampToRFC3339UTCOffset(object):
class TestTimestampToRFC3339LocalOffsetLondon(object): class TestTimestampToRFC3339LocalOffsetLondon(object):
def setup(self): def setup(self):
environ = os.environ.copy() self.old = os.environ.get("TZ", None)
environ["TZ"] = "Europe/London" os.environ["TZ"] = "Europe/London"
time.tzset()
self.mod = ProxyFunctionModule("tests/rfc3339", environ=environ) self.mod = ProxyFunctionModule("tests/rfc3339", environ=os.environ)
self.func = self.mod.timestamp_to_rfc3339_localoffset self.func = self.mod.timestamp_to_rfc3339_localoffset
def teardown(self): def teardown(self):
if self.old is None:
del os.environ["TZ"]
else:
os.environ["TZ"] = self.old
time.tzset()
self.mod.close() self.mod.close()
def test_simple_cases(self): def test_simple_cases(self):
@ -244,13 +257,20 @@ class TestTimestampToRFC3339LocalOffsetLondon(object):
class TestTimestampToRFC3339LocalOffsetNewYork(object): class TestTimestampToRFC3339LocalOffsetNewYork(object):
def setup(self): def setup(self):
environ = os.environ.copy() self.old = os.environ.get("TZ", None)
environ["TZ"] = "America/New_York" os.environ["TZ"] = "America/New_York"
time.tzset()
self.mod = ProxyFunctionModule("tests/rfc3339", environ=environ) self.mod = ProxyFunctionModule("tests/rfc3339", environ=os.environ)
self.func = self.mod.timestamp_to_rfc3339_localoffset self.func = self.mod.timestamp_to_rfc3339_localoffset
def teardown(self): def teardown(self):
if self.old is None:
del os.environ["TZ"]
else:
os.environ["TZ"] = self.old
time.tzset()
self.mod.close() self.mod.close()
def test_simple_cases(self): def test_simple_cases(self):

Wyświetl plik

@ -36,10 +36,13 @@ int main(int argc, char **argv)
} }
} }
void reply(const Json::Value &what) void reply(const Json::Value &arg1, const Json::Value &arg2)
{ {
Json::Value response(Json::arrayValue);
response.append(arg1);
response.append(arg2);
Json::FastWriter writer; Json::FastWriter writer;
cout << writer.write(what); cout << writer.write(response);
} }
void handle_command(const Json::Value &command) void handle_command(const Json::Value &command)
@ -58,18 +61,29 @@ void handle_command(const Json::Value &command)
int_arg = command[1u].asLargestInt(); int_arg = command[1u].asLargestInt();
} }
if (command_name == "validate_rfc3339") try
reply(RFC3339::validate_rfc3339(string_arg)); {
else if (command_name == "rfc3339_to_timestamp") if (command_name == "validate_rfc3339")
reply(RFC3339::rfc3339_to_timestamp(string_arg)); reply("return", RFC3339::validate_rfc3339(string_arg));
else if (command_name == "timestamp_to_rfc3339_utcoffset") else if (command_name == "rfc3339_to_timestamp")
reply(RFC3339::timestamp_to_rfc3339_utcoffset(int_arg)); reply("return", RFC3339::rfc3339_to_timestamp(string_arg));
else if (command_name == "timestamp_to_rfc3339_localoffset") else if (command_name == "timestamp_to_rfc3339_utcoffset")
reply(RFC3339::timestamp_to_rfc3339_localoffset(int_arg)); reply("return", RFC3339::timestamp_to_rfc3339_utcoffset(int_arg));
else if (command_name == "now_to_rfc3339_utcoffset") else if (command_name == "timestamp_to_rfc3339_localoffset")
reply(RFC3339::now_to_rfc3339_utcoffset()); reply("return", RFC3339::timestamp_to_rfc3339_localoffset(int_arg));
else if (command_name == "now_to_rfc3339_localoffset") else if (command_name == "now_to_rfc3339_utcoffset")
reply(RFC3339::now_to_rfc3339_localoffset()); reply("return", RFC3339::now_to_rfc3339_utcoffset());
else else if (command_name == "now_to_rfc3339_localoffset")
throw runtime_error("Command not found"); reply("return", RFC3339::now_to_rfc3339_localoffset());
else
throw runtime_error("Command not found");
}
catch (out_of_range &e)
{
reply("time_t error", false);
}
catch (exception &e)
{
reply("exception", e.what());
}
} }

Wyświetl plik

@ -14,6 +14,7 @@ import uuid
import copy import copy
import random import random
import xml.etree.cElementTree as ET import xml.etree.cElementTree as ET
import urllib
class ProxyException: class ProxyException:
def __init__(self, name, what=None): def __init__(self, name, what=None):
@ -252,7 +253,7 @@ class MockHTTPHandler(BaseHTTPServer.BaseHTTPRequestHandler):
e = self.server.expect_queue.popleft() e = self.server.expect_queue.popleft()
self.compare(e["method"], self.command, "method") self.compare(e["method"], self.command, "method")
self.compare(e["path"], self.path, "path") self.compare(e["path"], urllib.unquote(self.path), "path")
expect_100_header = self.headers.getheader('expect') expect_100_header = self.headers.getheader('expect')
expect_100 = expect_100_header and \ expect_100 = expect_100_header and \
@ -740,13 +741,10 @@ class TestCPPConnector:
fake_view_response = \ fake_view_response = \
{"total_rows": len(rows), "offset": 0, "rows": rows} {"total_rows": len(rows), "offset": 0, "rows": rows}
# cURL is a little overzealous with its escape(): _ is replaced
# with %5F. This should be fine
self.callbacks.advance_time(1925) self.callbacks.advance_time(1925)
view_time = self.callbacks.time_project(1925) view_time = self.callbacks.time_project(1925)
view_path = "_design/flight/_view/end%5Fstart%5Fincluding%5Fpayloads" view_path = "_design/flight/_view/end_start_including_payloads"
options = "include%5Fdocs=true&startkey=%5B{0}%5D".format(view_time) options = "include_docs=true&startkey=[{0}]".format(view_time)
self.couchdb.expect_request( self.couchdb.expect_request(
path=self.db_path + view_path + "?" + options, path=self.db_path + view_path + "?" + options,
@ -766,8 +764,8 @@ class TestCPPConnector:
fake_view_response = \ fake_view_response = \
{"total_rows": len(rows), "offset": 0, "rows": rows} {"total_rows": len(rows), "offset": 0, "rows": rows}
view_path = "_design/payload%5Fconfiguration/_view/name%5Ftime%5Fcreated" view_path = "_design/payload_configuration/_view/name_time_created"
options = "include%5Fdocs=true" options = "include_docs=true"
self.couchdb.expect_request( self.couchdb.expect_request(
path=self.db_path + view_path + "?" + options, path=self.db_path + view_path + "?" + options,

Wyświetl plik

@ -140,14 +140,14 @@ int main(int argc, char **argv)
else else
report_result("return"); report_result("return");
} }
catch (runtime_error e) catch (runtime_error &e)
{ {
if (e.what() == string("invalid command name")) if (e.what() == string("invalid command name"))
throw; throw;
report_result("error", "runtime_error", e.what()); report_result("error", "runtime_error", e.what());
} }
catch (invalid_argument e) catch (invalid_argument &e)
{ {
report_result("error", "invalid_argument", e.what()); report_result("error", "invalid_argument", e.what());
} }