Skip to content

RavenDB-27141 Seed test databases from a .ravendbdump - #23

Open
poissoncorp wants to merge 1 commit into
ravendb:v7.2from
poissoncorp:RavenDB-27141-dump-seeding
Open

poissoncorp wants to merge 1 commit into
ravendb:v7.2from
poissoncorp:RavenDB-27141-dump-seeding

Conversation

@poissoncorp

Copy link
Copy Markdown
Contributor

Closes the last gap against src/Raven.TestDriver: DatabaseDumpFilePath and DatabaseDumpFileStream. It was blocked on the client having no smuggler, which ravendb 7.2.6 shipped.

python -m unittest discover -s tests

72 tests, nothing skipped.


New features

Seed every test database from a dump

Writing fixture documents by hand in setup_database stops being the only option. Point the driver at a .ravendbdump and every database it creates is imported from it, before setup_database runs.

class PeopleTestDriver(RavenTestDriver):
    def database_dump_file_path(self):
        return "fixtures/people.ravendbdump"


with PeopleTestDriver() as driver:
    with driver.get_document_store() as store:
        with store.open_session() as session:
            assert session.load("people/1", Person).name == "Ayende"

database_dump_file_stream() takes an open binary stream instead of a path, for a fixture that ships inside a package:

class PeopleTestDriver(RavenTestDriver):
    def database_dump_file_stream(self):
        return importlib.resources.files("tests.fixtures").joinpath("people.ravendbdump").open("rb")

The driver asks that hook once per driver, rewinds the stream between databases, and closes it when the driver closes. C# re-reads the virtual property, so a getter returning a fresh stream leaks one per store and disposes only the last; asking once avoids that.

Produce a dump from a database you already have:

store.smuggler.for_database(store.database).export(DatabaseSmugglerExportOptions(), "people.ravendbdump")

Breaking changes

The client floor moves to 7.2.6

store.smuggler does not exist before it.

install_requires=["ravendb-embedded~=7.2.5", "ravendb~=7.2.6"]

A suite pinned to an older ravendb keeps the previous test driver release; nothing else in this version needs 7.2.6.


Verification

  • Round trip against a real server: two documents are seeded into a database, exported to a dump, then two fresh databases are created through the hook and both contain them.
  • The stream hook is asserted to be asked once across two databases, and its stream to be closed after driver.close().
  • The no-dump path is asserted to leave a database empty, so the import is genuinely skipped rather than silently importing nothing.
  • black --check clean, labs 02, 03 and 05 pass.

The client shipped a smuggler in 7.2.6, so DatabaseDumpFilePath and DatabaseDumpFileStream can finally be ported. The stream hook is asked once per driver and rewound between databases, which C# does not do.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant