Skip to content

Commit

Permalink
feat(tests): ioredis being able to successfully run tests, make it re…
Browse files Browse the repository at this point in the history
…ady to be part of CI

Signed-off-by: Boaz Sade <boaz@dragonflydb.io>
  • Loading branch information
boazsade committed Nov 6, 2022
1 parent e46e581 commit 0229211
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 16 deletions.
38 changes: 24 additions & 14 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,35 @@ docker run --network=host node-redis-test npm run test -w ./packages/client -- -
In general, you can add this way any option from [mocha framework](https://mochajs.org/#command-line-usage).

## ioredis
NOTE: we are depending on some changes to ioredis test, in order to pass more tests, as we are currently failing
because in monitor command we always returning the command name in upper case, and the tests expected it to
be in lower case.

Integration tests for ioredis client.
[ioredis](https://github.com/luin/ioredis) is a robust, performance-focused and full-featured Redis client for Node.js.
It contains a very extensive test coverage for Redis. Currently not all features are supported by Dragonfly.
As such please use the scripts for running the test successfully -
**[run_ioredis_on_docker.sh](./integration/run_ioredis_on_docker.sh)**: to run the supported tests on a docker image
Please note that you can run this script in tow forms:

If the image is already build:
```
./integration/run_ioredis_on_docker
```

A more safe way is to build the image (or ensure that it is up to date), and then execute the tests:
```
./integration/run_ioredis_on_docker --build
```
The the "--build" first build the image and then execute the tests.
Please do not try to run out of docker image as this brigs the correct version and patch some tests.
Please note that the script only run tests that are currently supported
You can just build the image with

Build:
```
docker build -t ioredis-test -f ./ioredis.Dockerfile .
```
Run:
```
docker run --network=host mocha [options]
```
The dockerfile already has an entrypoint setup. This way, you can add your own arguments to the mocha command.

Example 1 - running all tests inside the `unit` directory:
```
docker run -it --network=host ioredis mocha "test/unit/**/*.ts"
```
Example 2 - running a single test by supplying the `--grep` option:
```
docker run -it --network=host ioredis mocha --grep "should properly mark commands as transactions" "test/unit/**/*.ts"
```

For more details on the entrypoint setup, compare the `ioredis.Dockerfile`
with the npm test script located on the `package.json` of the ioredis project.
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Dockerfile
*.Dockerfile
stress_shutdown.sh
get_sets.sh
async.py
generate_sets.py
venv
6 changes: 6 additions & 0 deletions tests/integration/.patch_ioredis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

# This script is only temporary until issue https://github.com/luin/ioredis/issues/1671 is resolved (hopefully soon)
# what we are doing here, is making sure that we would not compare the result case sensitive.
sed -i 's/expect(args\[0\]).to.eql("get")/expect(args\[0\]).to.match(\/get\/i)/' $1
sed -i 's/args\[0\] === "set"/args\[0\] === "set" || args\[0\] === "SET"/' $1
29 changes: 29 additions & 0 deletions tests/integration/.run_ioredis_valid_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

# The following tests are not supported
#"should reconnect if reconnectOnError
# should reload scripts on redis restart
# should check and load uniq scripts only
# supported in transaction blocks
# rejects when monitor is disabled"
# should resend unfulfilled commands to the correct
# should set the name before any subscribe
# should name the connection if options
# scanStream
# scripting
# should affect the old way
# should support Map
# should support object
# should batch all commands before ready event
# should support key prefixing for sort
# should be sent on the connect event

## Some issues that are still open need to be resolved such as
# https://github.com/dragonflydb/dragonfly/issues/457
# and https://github.com/dragonflydb/dragonfly/issues/458


TS_NODE_TRANSPILE_ONLY=true NODE_ENV=test mocha \
"test/helpers/*.ts" "test/unit/**/*.ts" "test/functional/**/*.ts" \
-g "should reconnect if reconnectOnError|should reload scripts on redis restart|should check and load uniq scripts only|should be supported in transaction blocks|rejects when monitor is disabled|should resend unfulfilled commands to the correct|should set the name before any subscribe|should name the connection if options|scanStream|scripting|should affect the old way|should support Map|should support object|should batch all commands before ready event|should support key prefixing for sort|should be sent on the connect event" \
--invert
20 changes: 18 additions & 2 deletions tests/integration/ioredis.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

FROM node:18.7.0
ENV NODE_ENV=development
ENV RUN_IN_DOCKER=1

WORKDIR /app

# Git
RUN apt -y install git
# Git
RUN apt update -y && apt install -y git

# Clone ioredis v5.2.3
RUN git clone --branch v5.2.3 https://github.com/luin/ioredis
Expand All @@ -15,4 +16,19 @@ WORKDIR /app/ioredis

RUN npm install

# This is required until https://github.com/luin/ioredis/issues/1671 is resolved.
ADD .patch_ioredis.sh patch_ioredis.sh

# Script to run the tests that curretly pass successfully.
# Note that in DF we still don't have support for cluster and we
# want to skip tests such as elasticache, also we have some issues that
# need to be resolved such as
# https://github.com/dragonflydb/dragonfly/issues/457
# and https://github.com/dragonflydb/dragonfly/issues/458
ADD .run_ioredis_valid_test.sh run_tests.sh

# this would enable running monitor commands successfully
# we may need to remove this incase we have other fix
RUN ./patch_ioredis.sh test/functional/monitor.ts

ENTRYPOINT [ "npm", "run", "env", "--", "TS_NODE_TRANSPILE_ONLY=true", "NODE_ENV=test" ]
19 changes: 19 additions & 0 deletions tests/integration/run_ioredis_on_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# Running this with --build would build the image as well
if [ "$1" = "--build" ]; then
docker build -t ioredis-test -f ./ioredis.Dockerfile . || {
echo "failed to build io redis image"
exit 1
}
fi

# run the tests
echo "runniing ioredis tess"
docker run --rm -i --network=host ioredis-test ./run_tests.sh
if [ $? -ne 0 ];then
echo "some tests failed - please look at the output from this run"
exit 1
else
echo "finish runing tests successfully"
exit 0
fi

0 comments on commit 0229211

Please sign in to comment.