Commit 337ed1f3 authored by Patrick Chen's avatar Patrick Chen

fix listen event bug

parent 7ad112c4
...@@ -9,9 +9,10 @@ int main() ...@@ -9,9 +9,10 @@ int main()
{ {
xs::ExchangeServer server("greeting", {}, {}, 0, nullptr); xs::ExchangeServer server("greeting", {}, {}, 0, nullptr);
server.onCmd( server.onCmd(
"GetGreetingMessage", "GetMessage",
[&server](const std::string&, const std::string&) { [&server](const std::string&, const std::string&) {
const auto name = server.runCmd("GetName", ""); const auto name = server.runCmd("GetName", "");
server.postEvent("NotifyGetMessage", "");
return "Hello, " + name + "!"; return "Hello, " + name + "!";
} }
); );
......
...@@ -3,14 +3,17 @@ ...@@ -3,14 +3,17 @@
{ {
"command": "GetName", "command": "GetName",
"response": "Master" "response": "Master"
},
{
"event": "NotifyGetMessage"
} }
], ],
"script": [ "script": [
{ {
"command": "GetGreetingMessage", "command": "GetMessage",
"expect": "Hello, Master!", "expect": "Hello, Master!",
"runs": ["GetName"], "runs": ["GetName"],
"posts": [] "posts": ["NotifyGetMessage"]
} }
] ]
} }
...@@ -106,9 +106,6 @@ std::string Tester::onCommand(const std::string& name, const std::string& params ...@@ -106,9 +106,6 @@ std::string Tester::onCommand(const std::string& name, const std::string& params
void Tester::onEvent(const std::string& name, const std::string& params) noexcept void Tester::onEvent(const std::string& name, const std::string& params) noexcept
{ {
const auto found = acceptEvents_.find(name);
const auto* service = std::get<1>(*found);
receivedEventCount_[name]++; receivedEventCount_[name]++;
} }
...@@ -118,6 +115,11 @@ void Tester::run() noexcept ...@@ -118,6 +115,11 @@ void Tester::run() noexcept
resetCounters(); resetCounters();
const auto response = server_.runCmd(expectation.name_, ""); const auto response = server_.runCmd(expectation.name_, "");
// wait 100ms for upcoming events
using namespace std::chrono_literals;
std::this_thread::sleep_for(100ms);
const auto report = createReport(response, expectation); const auto report = createReport(response, expectation);
if (report.pass) { if (report.pass) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment