mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-14 19:44:05 +08:00
Revert "params: safe and efficient async writing parameters (#25912)"
This reverts commit 780669c33fea1b2a14a0bd6e2eac82c9b8893aa5. old-commit-hash: ec479322d3d8d789290bee68919d14b040481d53
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
#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");
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import time
|
||||
import uuid
|
||||
import unittest
|
||||
|
||||
from openpilot.common.params import Params, ParamKeyType, UnknownKeyName
|
||||
from openpilot.common.params import Params, ParamKeyType, UnknownKeyName, put_nonblocking, put_bool_nonblocking
|
||||
|
||||
class TestParams(unittest.TestCase):
|
||||
def setUp(self):
|
||||
@@ -86,7 +86,7 @@ class TestParams(unittest.TestCase):
|
||||
q = Params()
|
||||
def _delayed_writer():
|
||||
time.sleep(0.1)
|
||||
Params().put_nonblocking("CarParams", "test")
|
||||
put_nonblocking("CarParams", "test")
|
||||
threading.Thread(target=_delayed_writer).start()
|
||||
assert q.get("CarParams") is None
|
||||
assert q.get("CarParams", True) == b"test"
|
||||
@@ -95,7 +95,7 @@ class TestParams(unittest.TestCase):
|
||||
q = Params()
|
||||
def _delayed_writer():
|
||||
time.sleep(0.1)
|
||||
Params().put_bool_nonblocking("CarParams", True)
|
||||
put_bool_nonblocking("CarParams", True)
|
||||
threading.Thread(target=_delayed_writer).start()
|
||||
assert q.get("CarParams") is None
|
||||
assert q.get("CarParams", True) == b"1"
|
||||
|
||||
Reference in New Issue
Block a user