mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-07-11 13:52:04 +08:00
08e70aecb2
* 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
---------
Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
old-commit-hash: 0d797f4e8b
28 lines
802 B
C++
28 lines
802 B
C++
#include "catch2/catch.hpp"
|
|
#define private public
|
|
#include "common/params.h"
|
|
#include "common/util.h"
|
|
|
|
TEST_CASE("Params/asyncWriter") {
|
|
char tmp_path[] = "/tmp/asyncWriter_XXXXXX";
|
|
const std::string param_path = mkdtemp(tmp_path);
|
|
Params params(param_path);
|
|
auto param_names = {"CarParams", "IsMetric"};
|
|
{
|
|
AsyncWriter async_writer;
|
|
for (const auto &name : param_names) {
|
|
async_writer.queue({param_path, name, "1"});
|
|
// param is empty
|
|
REQUIRE(params.get(name).empty());
|
|
}
|
|
|
|
// check if thread is running
|
|
REQUIRE(async_writer.future.valid());
|
|
REQUIRE(async_writer.future.wait_for(std::chrono::milliseconds(0)) == std::future_status::timeout);
|
|
}
|
|
// check results
|
|
for (const auto &name : param_names) {
|
|
REQUIRE(params.get(name) == "1");
|
|
}
|
|
}
|