Skip to content

Add playback tests; test against executable servers#516

Merged
lossyrob merged 33 commits intomainfrom
feature/rde/playback
Feb 26, 2025
Merged

Add playback tests; test against executable servers#516
lossyrob merged 33 commits intomainfrom
feature/rde/playback

Conversation

@lossyrob
Copy link
Copy Markdown
Contributor

@lossyrob lossyrob commented Feb 25, 2025

This PR adds way to record messages received and sent by the PGTS server, and to play back those messages to test they produce the same results.

It also enables the client wrapper around a message server to be used against an executable, which allows us to test built pgtoolsservice executables.

It also adds the concept of Datasets for tests, which can be loaded into the database temporary for testing purposes. The pagila dataset is included.

Also includes some refactors and improvements. See commits for individual changes.

Pylance shows a type error for passing a string into cursor.execute and other methods, which are typed expecting psycopg.sql.SQL or variants. Also, sql.SQL is typed as a Literal[string], and so type errors would occur for non-literal strings. This change pushes the # type:ignore to a single place and uses the as_sql method to convert from str -> sql.SQL.
Some message IDs are ints, this was discovered during recording/playback
This file encodes the Language Server Protocol (LSP) into pydantic models.

While these classes could replace JSONRPCMessage, this refactor is left as future work. These models are used for message recording and testing purposes for now.
Also better deserialization error handling.
This allows other implementations of RPC servers, such as a queue-based server that will be used in testing.
This list of services can now be used in testing.
This allows more explicit typing for outbound messages.
This will allow us to test recorded sessions against a fresh database.
This will allow us to load known datasets into tests.

Adds the pagila dataset.
This creates a testable client to send messages to a server and await messages from it. It can be used with a Queue-based message server to produce an in-process message server, and will also be able to handle running bundled EXE rpc servers for additional testing.
Use MockMessageServerClientWrapper in tests. Fixtures for loading datasets into the integration test database, along with the PlaybackDB which uses a new docker container running at port 5678 to isolate database initialization for repeatable playback testing.
This test will work against a built server as a simple smoke test to ensure it runs successfully
@lossyrob lossyrob requested review from a team as code owners February 25, 2025 03:11
Also added docker-compose.recording.yml and scripts/load_test_data.sh
for recording playback and loading test data into development environment.
Copy link
Copy Markdown
Member

@mmcfarland mmcfarland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small typos, but looks great. Ran through and executed the tests, also recorded my own new smoke test file and added passing tests. The whole thing is pretty nifty, honestly.

Comment thread ossdbtoolsservice/main.py Outdated
Comment thread DEVELOPING.md Outdated
@lossyrob lossyrob merged commit a5e82b6 into main Feb 26, 2025
@lossyrob lossyrob deleted the feature/rde/playback branch February 26, 2025 18:32
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.

2 participants