MCPcopy Create free account
hub / github.com/FastLED/FastLED / FL_TEST_FILE

Function FL_TEST_FILE

tests/fl/stl/asio/http/http_promise.cpp:14–315  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12#include "fl/stl/asio/http/test_utils/mock_http_client.h"
13
14FL_TEST_FILE(FL_FILEPATH) {
15
16using namespace fl;
17using namespace fl::net::http;
18
19//=============================================================================
20// TEST CASE: SYNC rpc() resolves with result
21//=============================================================================
22
23FL_TEST_CASE("Promise - SYNC rpc() resolves") {
24 MockHttpServer server(48001);
25 server.connect();
26
27 Remote remoteServer(
28 [&server]() { return server.readRequest(); },
29 [&server](const json& r) { server.writeResponse(r); }
30 );
31
32 remoteServer.bind("add", [](int a, int b) -> int {
33 return a + b;
34 });
35
36 MockHttpClient client(server);
37 client.connect();
38
39 // Use rpc() API
40 json params = json::array();
41 params.push_back(json(5));
42 params.push_back(json(7));
43 fl::task::Promise<json> p = client.rpc("add", params);
44
45 FL_CHECK(p.valid());
46 FL_CHECK(!p.is_completed());
47
48 // Pump: server reads from client, processes, sends response back
49 server.update(0);
50 remoteServer.update(0);
51
52 // Client update drains chunks and resolves promise
53 client.update(0);
54
55 FL_REQUIRE(p.is_resolved());
56 const json& response = p.value();
57 FL_CHECK(response.contains("result"));
58 FL_CHECK_EQ(response["result"].as_int().value(), 12);
59}
60
61//=============================================================================
62// TEST CASE: ASYNC rpc() skips ACK, resolves with final result
63//=============================================================================
64
65FL_TEST_CASE("Promise - ASYNC rpc() skips ACK") {
66 MockHttpServer server(48002);
67 server.connect();
68 server.update(0);
69
70 Remote remoteServer(
71 [&server]() { return server.readRequest(); },

Callers

nothing calls this directly

Calls 15

readRequestMethod · 0.80
writeResponseMethod · 0.80
rpcMethod · 0.80
sendUpdateMethod · 0.80
sendFinalMethod · 0.80
rpcStreamMethod · 0.80
arrayClass · 0.50
jsonClass · 0.50
connectMethod · 0.45
bindMethod · 0.45
push_backMethod · 0.45
validMethod · 0.45

Tested by

no test coverage detected