move lock clearing to uploader (#23826)
* move lock clearing to uploader * test casepull/23829/head
parent
de178ea79c
commit
3243d1a81e
|
@ -51,8 +51,6 @@ static kj::Array<capnp::word> build_boot_log() {
|
|||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
clear_locks(LOG_ROOT);
|
||||
|
||||
const std::string path = LOG_ROOT + "/boot/" + logger_get_route_name() + ".bz2";
|
||||
LOGW("bootlog to %s", path.c_str());
|
||||
|
||||
|
|
|
@ -267,15 +267,3 @@ void lh_close(LoggerHandle* h) {
|
|||
}
|
||||
pthread_mutex_unlock(&h->lock);
|
||||
}
|
||||
|
||||
int clear_locks_fn(const char* fpath, const struct stat *sb, int tyupeflag) {
|
||||
const char* dot = strrchr(fpath, '.');
|
||||
if (dot && strcmp(dot, ".lock") == 0) {
|
||||
unlink(fpath);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void clear_locks(const std::string log_root) {
|
||||
ftw(log_root.c_str(), clear_locks_fn, 16);
|
||||
}
|
||||
|
|
|
@ -96,4 +96,3 @@ void logger_log(LoggerState *s, uint8_t* data, size_t data_size, bool in_qlog);
|
|||
|
||||
void lh_log(LoggerHandle* h, uint8_t* data, size_t data_size, bool in_qlog);
|
||||
void lh_close(LoggerHandle* h);
|
||||
void clear_locks(const std::string log_root);
|
||||
|
|
|
@ -14,7 +14,8 @@ def create_random_file(file_path, size_mb, lock=False):
|
|||
pass
|
||||
|
||||
lock_path = file_path + ".lock"
|
||||
os.close(os.open(lock_path, os.O_CREAT | os.O_EXCL))
|
||||
if lock:
|
||||
os.close(os.open(lock_path, os.O_CREAT | os.O_EXCL))
|
||||
|
||||
chunks = 128
|
||||
chunk_bytes = int(size_mb * 1024 * 1024 / chunks)
|
||||
|
@ -24,9 +25,6 @@ def create_random_file(file_path, size_mb, lock=False):
|
|||
for _ in range(chunks):
|
||||
f.write(data)
|
||||
|
||||
if not lock:
|
||||
os.remove(lock_path)
|
||||
|
||||
class MockResponse():
|
||||
def __init__(self, text, status_code):
|
||||
self.text = text
|
||||
|
|
|
@ -91,21 +91,3 @@ TEST_CASE("trigger_rotate") {
|
|||
REQUIRE(frame_id == start_frame_id + encoder_seg * (SEGMENT_LENGTH * MAIN_FPS));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("clear_locks") {
|
||||
std::vector<std::string> dirs;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
std::string &path = dirs.emplace_back(LOG_ROOT + "/" + std::to_string(i));
|
||||
REQUIRE(util::create_directories(path, 0775));
|
||||
std::ofstream{path + "/.lock"};
|
||||
REQUIRE(util::file_exists(path + "/.lock"));
|
||||
}
|
||||
|
||||
clear_locks(LOG_ROOT);
|
||||
|
||||
for (const auto &dir : dirs) {
|
||||
std::string lock_file = dir + "/.lock";
|
||||
REQUIRE(util::file_exists(lock_file) == false);
|
||||
rmdir(dir.c_str());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,9 +133,11 @@ class TestUploader(UploaderTestCase):
|
|||
self.assertTrue(log_handler.upload_order == exp_order, "Files uploaded in wrong order")
|
||||
|
||||
def test_no_upload_with_lock_file(self):
|
||||
self.start_thread()
|
||||
|
||||
time.sleep(0.25)
|
||||
f_paths = self.gen_files(lock=True, boot=False)
|
||||
|
||||
self.start_thread()
|
||||
# allow enough time that files should have been uploaded if they would be uploaded
|
||||
time.sleep(5)
|
||||
self.join_thread()
|
||||
|
@ -144,5 +146,15 @@ class TestUploader(UploaderTestCase):
|
|||
self.assertFalse(getxattr(f_path, uploader.UPLOAD_ATTR_NAME), "File upload when locked")
|
||||
|
||||
|
||||
def test_clear_locks_on_startup(self):
|
||||
f_paths = self.gen_files(lock=True, boot=False)
|
||||
self.start_thread()
|
||||
time.sleep(1)
|
||||
self.join_thread()
|
||||
|
||||
for f_path in f_paths:
|
||||
self.assertFalse(os.path.isfile(f_path + ".lock"), "File lock not cleared on startup")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main(failfast=True)
|
||||
|
|
|
@ -213,6 +213,8 @@ class Uploader():
|
|||
return msg
|
||||
|
||||
def uploader_fn(exit_event):
|
||||
clear_locks(ROOT)
|
||||
|
||||
params = Params()
|
||||
dongle_id = params.get("DongleId", encoding='utf8')
|
||||
|
||||
|
|
Loading…
Reference in New Issue