common/params: support nonblocking write (#29808)
* Safe and efficient asynchronous writing parameters * call putNonBlocking in locationd * remove space * ->AsyncWriter * remove semicolon * use member function * asyc write multiple times * add test case for AsyncWriter * merge master * add missing include * public * cleanup * create once * cleanup * update that * explicit waiting * improve test case * pass prefix to asywriter * move to params * assert(queue.empty()) * add comment * add todo * test_power_monitoring: remove patch * rm laikad.py * fix import --------- Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>pull/30721/head
parent
fcc671297e
commit
3c4c4d1f7f
14 changed files with 111 additions and 42 deletions
@ -0,0 +1,27 @@ |
||||
#include "catch2/catch.hpp" |
||||
#define private public |
||||
#include "common/params.h" |
||||
#include "common/util.h" |
||||
|
||||
TEST_CASE("params_nonblocking_put") { |
||||
char tmp_path[] = "/tmp/asyncWriter_XXXXXX"; |
||||
const std::string param_path = mkdtemp(tmp_path); |
||||
auto param_names = {"CarParams", "IsMetric"}; |
||||
{ |
||||
Params params(param_path); |
||||
for (const auto &name : param_names) { |
||||
params.putNonBlocking(name, "1"); |
||||
// param is empty
|
||||
REQUIRE(params.get(name).empty()); |
||||
} |
||||
|
||||
// check if thread is running
|
||||
REQUIRE(params.future.valid()); |
||||
REQUIRE(params.future.wait_for(std::chrono::milliseconds(0)) == std::future_status::timeout); |
||||
} |
||||
// check results
|
||||
Params p(param_path); |
||||
for (const auto &name : param_names) { |
||||
REQUIRE(p.get(name) == "1"); |
||||
} |
||||
} |
Loading…
Reference in new issue