summaryrefslogtreecommitdiff
path: root/indra/llcorehttp/tests
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcorehttp/tests')
-rw-r--r--[-rwxr-xr-x]indra/llcorehttp/tests/llcorehttp_test.cpp1
-rw-r--r--indra/llcorehttp/tests/test_httprequest.hpp15
-rw-r--r--indra/llcorehttp/tests/test_jsonrpcws.hpp146
3 files changed, 147 insertions, 15 deletions
diff --git a/indra/llcorehttp/tests/llcorehttp_test.cpp b/indra/llcorehttp/tests/llcorehttp_test.cpp
index c7c50e6166..65d7fe93a9 100755..100644
--- a/indra/llcorehttp/tests/llcorehttp_test.cpp
+++ b/indra/llcorehttp/tests/llcorehttp_test.cpp
@@ -44,6 +44,7 @@
#include "test_httprequest.hpp"
#include "test_httpheaders.hpp"
#include "test_httprequestqueue.hpp"
+#include "test_jsonrpcws.hpp"
#include "_httpservice.h"
#include "llproxy.h"
diff --git a/indra/llcorehttp/tests/test_httprequest.hpp b/indra/llcorehttp/tests/test_httprequest.hpp
index 77ed8df066..68f8c4f71f 100644
--- a/indra/llcorehttp/tests/test_httprequest.hpp
+++ b/indra/llcorehttp/tests/test_httprequest.hpp
@@ -2744,13 +2744,6 @@ void HttpRequestTestObjectType::test<22>()
set_test_name("BUG-2295");
-#if LL_WINDOWS && ADDRESS_SIZE == 64
- // teamcity win64 builds freeze on this test, if you figure out the cause, please fix it
- if (getenv("TEAMCITY_PROJECT_NAME"))
- {
- skip("BUG-2295 - partial load on W64 causes freeze");
- }
-#endif
// Handler can be stack-allocated *if* there are no dangling
// references to it after completion of this method.
// Create before memory record as the string copy will bump numbers.
@@ -2924,14 +2917,6 @@ void HttpRequestTestObjectType::test<23>()
set_test_name("HttpRequest GET 503s with 'Retry-After'");
-#if LL_WINDOWS && ADDRESS_SIZE == 64
- // teamcity win64 builds freeze on this test, if you figure out the cause, please fix it
- if (getenv("TEAMCITY_PROJECT_NAME"))
- {
- skip("llcorehttp 503-with-retry test hangs on Windows 64");
- }
-#endif
-
// This tests mainly that the code doesn't fall over if
// various well- and mis-formed Retry-After headers are
// sent along with the response. Direct inspection of
diff --git a/indra/llcorehttp/tests/test_jsonrpcws.hpp b/indra/llcorehttp/tests/test_jsonrpcws.hpp
new file mode 100644
index 0000000000..6cf7932aa0
--- /dev/null
+++ b/indra/llcorehttp/tests/test_jsonrpcws.hpp
@@ -0,0 +1,146 @@
+/**
+ * @file test_jsonrpcws.hpp
+ * @brief unit tests for LLJSONRPCConnection helpers and dispatch behavior
+ */
+
+#ifndef TEST_LLCORE_JSONRPCWS_H_
+#define TEST_LLCORE_JSONRPCWS_H_
+
+#include "lljsonrpcws.h"
+#include "lltimer.h"
+
+namespace
+{
+class TestJSONRPCConnection : public LLJSONRPCConnection
+{
+public:
+ TestJSONRPCConnection()
+ : LLJSONRPCConnection(LLWebsocketMgr::WSServer::ptr_t(), LLWebsocketMgr::connection_h())
+ {
+ }
+
+ using LLJSONRPCConnection::processMessage;
+ using LLJSONRPCConnection::validateMessage;
+ using LLJSONRPCConnection::testInjectPendingRequest;
+ using LLJSONRPCConnection::testPendingRequestCount;
+ using LLJSONRPCConnection::testSweepTimeouts;
+};
+}
+
+namespace tut
+{
+ struct JSONRPCWSTestData
+ {
+ };
+
+ typedef test_group<JSONRPCWSTestData> JSONRPCWSTestGroupType;
+ typedef JSONRPCWSTestGroupType::object JSONRPCWSTestObjectType;
+ JSONRPCWSTestGroupType JSONRPCWSTestGroup("LLJSONRPCConnection Tests");
+
+ template<> template<>
+ void JSONRPCWSTestObjectType::test<1>()
+ {
+ set_test_name("makeEnvelope notification omits id");
+
+ LLSD params;
+ params["value"] = 42;
+ LLSD env = LLJSONRPCConnection::makeEnvelope(LLSD(), "runtime.debug", params, LLSD(), LLSD());
+
+ ensure("jsonrpc field should exist", env.has("jsonrpc"));
+ ensure_equals("jsonrpc version", env["jsonrpc"].asString(), "2.0");
+ ensure("notification should omit id", !env.has("id"));
+ ensure_equals("method", env["method"].asString(), "runtime.debug");
+ ensure_equals("param round trip", env["params"]["value"].asInteger(), 42);
+ }
+
+ template<> template<>
+ void JSONRPCWSTestObjectType::test<2>()
+ {
+ set_test_name("makeEnvelope response keeps id slot");
+
+ LLSD env = LLJSONRPCConnection::makeEnvelope(LLSD(), std::string(), LLSD(), LLSD("ok"), LLSD());
+
+ ensure("response should include id", env.has("id"));
+ ensure("response should not include method", !env.has("method"));
+ ensure_equals("result", env["result"].asString(), "ok");
+ }
+
+ template<> template<>
+ void JSONRPCWSTestObjectType::test<3>()
+ {
+ set_test_name("validateMessage accepts valid request and rejects invalid params");
+
+ TestJSONRPCConnection conn;
+
+ LLSD valid;
+ valid["jsonrpc"] = "2.0";
+ valid["method"] = "session.ping";
+ LLSD params = LLSD::emptyMap();
+ params["timestamp"] = 123;
+ valid["params"] = params;
+ ensure("valid request should pass", conn.validateMessage(valid, true));
+
+ LLSD invalid = valid;
+ invalid["params"] = "not-an-array-or-object";
+ ensure("invalid params type should fail", !conn.validateMessage(invalid, true));
+ }
+
+ template<> template<>
+ void JSONRPCWSTestObjectType::test<4>()
+ {
+ set_test_name("processMessage dispatches notification handler");
+
+ TestJSONRPCConnection conn;
+
+ bool called = false;
+ LLSD seen_id;
+ LLSD seen_params;
+ conn.registerMethod("runtime.debug",
+ [&](const std::string& method, const LLSD& id, const LLSD& params) -> LLSD
+ {
+ called = true;
+ ensure_equals("method propagated", method, "runtime.debug");
+ seen_id = id;
+ seen_params = params;
+ return LLSD();
+ });
+
+ LLSD params;
+ params["message"] = "hello";
+ LLSD notification = LLJSONRPCConnection::makeEnvelope(LLSD(), "runtime.debug", params, LLSD(), LLSD());
+ conn.processMessage(notification);
+
+ ensure("handler should be called", called);
+ ensure("notification id should be undefined", seen_id.isUndefined());
+ ensure_equals("payload should be forwarded", seen_params["message"].asString(), "hello");
+ }
+
+ template<> template<>
+ void JSONRPCWSTestObjectType::test<5>()
+ {
+ set_test_name("sweepTimeouts expires overdue callbacks");
+
+ TestJSONRPCConnection conn;
+
+ bool callback_called = false;
+ conn.testInjectPendingRequest(
+ "req_1",
+ LLTimer::getTotalSeconds() - 1.0,
+ [&](const LLSD& result, const LLSD& error)
+ {
+ callback_called = true;
+ ensure("timed out result should be undefined", result.isUndefined());
+ ensure_equals(
+ "timeout code",
+ error["code"].asInteger(),
+ LLJSONRPCConnection::RPCError::REQUEST_TIMEOUT);
+ });
+
+ ensure_equals("pending request should be tracked", conn.testPendingRequestCount(), (size_t)1);
+ conn.testSweepTimeouts();
+ ensure("timeout callback should be called", callback_called);
+ ensure_equals("pending request should be removed", conn.testPendingRequestCount(), (size_t)0);
+ }
+}
+
+#endif \ No newline at end of file