This tool may be used to backup and restore Moonraker's lmdb
database without depending on the "lmdb-utils" package. The
backup is done to a plain text file in cdb format, so a backup
may be restored on any platform.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Initialize the temporary directory in a "session_args" fixture that is session
scoped. Move the Klippy process to a session scope, restarting the process
only when necessary. This combination speeds up tests as it reduces disk
I/O and the overhead of starting the Klippy process for each test.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This makes the order in which they are reported consistent,
as the namespaces are stored in a set.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Correctly encode the query string. Use the query string for DELETE
requests in addition to GET requests.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
It is possible to reduce to a value that is not a dict in "insert_item()"
and "update_item()". Raise a ServerError with a clear description of
what went wrong in these situations.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
It is possible that Moonraker can be instantiated while the eventloop
is running during tests. To avoid errors allow synchronous calls until
the server starts.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Since the User DB is not going to be large cache the users
in local memory and sync with the DB when changes are
made to the local user store.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Now that all transactions run in a thread it is possible for them to
interleave. The record based operations allow for batch operations
within a single transaction.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Wrap command implementations in with a _run_command() method. All
database commands now return a Future object. If the command was
run before the eventloop starts its possible to immediately query
the Future's result.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Similar to the update method, however sync will remove any
keys in the database not in the new value.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Rather than creating two wrappers, use a single wrapper whose methods
always return a future or awaitable. If the operation occurs during
the __init__() method of a component it will be syncrhonous, and the
result from the future can be immediately queried.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Rather than reading out the entire database, attempt to pop off
empty keys in each database. This should should speed up
init on platforms with slow disk I/O and prevents reading
large namespaces in memory.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
It isn't necessary to read out the entire namespace, just attempt
to fetch the record and reduce the key list.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Since transactions are now threaded we need updating
and clearing a namespace needs to be performed within
one transaction.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Database transactions can perform disk I/O tasks, which at times will
block the eventloop. Run all transactions in threads to prevent this
from occuring.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This adds the framework for unit testing Moonraker via pytest.
Initally only moonraker.py, klippy_connection.py, and confighelper.py
have acceptable coverage. Coverage for other modules will be added on
an incremental basis, when most of Moonraker's source is covered tests
will be conducted via GitHub actions.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The read() method will return an empty list if the file specified
does not exist or if the read failed in some fashion.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>