dragonfly/tests
Vladislav add252c301
fix(server): Fix QUIT not shutting down connection (#280)
* fix(server): Fix QUIT not shutting down connection

Fixes #170
2022-09-13 05:25:46 +03:00
..
dragonfly fix(server): Fix QUIT not shutting down connection (#280) 2022-09-13 05:25:46 +03:00
README.md feat(server): Implemented periodic snapshotting (#161) (#250) 2022-08-26 13:54:38 +03:00
async.py fix(transaction): Fix rare deadlock case - fixes #150. (#155) 2022-06-15 16:53:27 +03:00
gen_sets.sh Add CONFIG RESETSTAT command. Start working on RPOPLPUSH 2022-04-27 23:50:03 +03:00
generate_sets.py Implement CLIENT LIST and CLIENT SETNAME. 2022-05-10 06:35:37 +03:00
jedis.Dockerfile feat(test): Add integration test for the jedis and node-redis clients (#233) 2022-08-12 22:42:54 +03:00
node-redis.Dockerfile fix(doc): add more examples on how to run node-redis test image 2022-08-15 08:37:28 +03:00
stress_shutdown.sh Upon full segment try unloading stash buckets back to regular ones 2022-05-12 13:43:03 +03:00

README.md

System tests

Pytest

The tests assume you have the "dragonfly" binary in <root>/build-dbg directory. You can override the location of the binary using DRAGONFLY_HOME environment var.

to run pytest, run: pytest -xv dragonfly

Writing tests

The Getting Started guide is a great resource to become familiar with writing pytest test cases.

Pytest will recursively search the tests/dragonfly directory for files matching the patterns test_*.py or *_test.py for functions matching these rules:

  • Functions or methods outside of a class prefixed by test
  • Functions or methods prefixed by test inside a class prefixed by Test (without an __init__ method)

Note: When making a new directory in tests/dragonfly be sure to create an __init__.py file to avoid name conflicts

Interacting with Dragonfly

Pytest allows for parameters with a specific name to be automatically resolved through fixtures for any test function. The following fixtures are to be used to interact with Dragonfly when writing a test:

Name Type Scope Description
tmp_dir pathlib.Path Session The temporary directory the Dragonfly binary will be running in. The environment variable DRAGONFLY_TMP is also set to this value
test_env dict Session The environment variables used when running Dragonfly as a dictionary
client redis.Redis Class The redis client to interact with the Dragonfly instance

To avoid the overhead of spawning a Dragonfly process for every test the client provided fixture has a Class scope which means that all test functions in the same class will interact with the same Dragonfly instance.

Passing CLI commands to Dragonfly

To pass custom flags to the Dragonfly executable two class decorators have been created. @dfly_args allows you to pass a list of parameters to the Dragonfly executable, similarly @dfly_multi_test_args allows you to specify multiple parameter configurations to test with a given test class.

In the case of @dfly_multi_test_args each parameter configuration will create one Dragonfly instance which each test will receive a client to as described in the above section

Parameters can use environmental variables with a formatted string where "{<VAR>}" will be replaced with the value of the <VAR> environment variable. Due to current pytest limtations fixtures cannot be passed to either of these decorators, this is currently the provided way to pass the temporary directory path in a CLI parameter.

Test Examples

  • blpop_test: Simple test case interacting with Dragonfly
  • snapshot_test: Example test using @dfly_args, environment variables and pre-test setup
  • key_limt_test: Example test using @dfly_multi_test_args

Integration tests

To simplify running integration test each package should have its own Dockerfile. The Dockerfile should contain everything needed in order to test the package against Drafongly. Docker can assume Dragonfly is running on localhost:6379. To run the test:

docker build -t [test-name] -f [test-dockerfile-name] .
docker run --network=host [test-name]

Node-Redis

Integration test for node-redis client. Build:

docker build -t node-redis-test -f ./node-redis.Dockerfile .

Run:

docker run --network=host node-redis-test

to run only selected tests use:

docker run --network=host node-redis-test npm run test -w ./packages/client -- --redis-version=2.8 -g <regex>

In general, you can add this way any option from mocha framework.

Jedis

Integration test for the Jedis client. Build:

docker build -t jedis-test -f ./jedis.Dockerfile .

Run:

docker run --network=host jedis-test