New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix redis test #15247
Merged
Merged
Fix redis test #15247
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/bin/bash | ||
|
||
function connect() { | ||
port=$1 | ||
a=$(redis-cli -p $port ping) # Connects to the redis server at the address 127.0.0.1 with $port. | ||
if [ "$a" = "PONG" ] | ||
then | ||
echo 'redis-server is running' | ||
else | ||
echo 'Failed: redis-server is not started' | ||
exit 1 | ||
fi | ||
} | ||
|
||
function exec_redis() { | ||
cmd=$1 | ||
expec_res=$2 | ||
res=$($cmd) | ||
if [ "$res" = "$expec_res" ] | ||
then | ||
echo "$cmd: $expec_res" | ||
else | ||
echo 'Failed: redis-cli command '"$cmd"' execution' | ||
exit 1 | ||
fi | ||
} | ||
|
||
## ==== Prepare environment ================================================= ## | ||
set -o pipefail | ||
connect 6379 | ||
# Execute redis-cli commands | ||
exec_redis 'redis-cli set foo bar' 'OK' | ||
exec_redis 'redis-cli get foo' 'bar' | ||
exec_redis 'redis-cli pfselftest' 'OK' | ||
exec_redis 'redis-cli flushdb' 'OK' | ||
out=$(redis-cli -p 6379 get foo) | ||
if [ "$out" = "" ] || [ $out = "(nil)" ] | ||
then | ||
echo "redis-cli -p 6379 get foo: $out" | ||
else | ||
echo 'Failed: redis-cli command 'redis-cli get foo' failed to execute' | ||
exit 1 | ||
fi | ||
|
||
# Load a test db from the data directory | ||
out=$(redis-cli -h localhost -p 6379 < ./movies.redis) | ||
exec_redis 'redis-cli HMGET movie:343 title' 'Spider-Man' | ||
|
||
# Connect to the new instance of redis-server with port 6380 and make 6380 instance a | ||
# replica of redis instance running on port 6379 and verify the result | ||
connect 6380 | ||
exec_redis 'redis-cli -p 6380 replicaof 127.0.0.1 6379' 'OK' | ||
sleep 10 | ||
|
||
out=$(redis-cli info replication) | ||
|
||
if [[ "$out" =~ "connected_slaves:1" ]] | ||
then | ||
echo "redis-cli info replication on master" | ||
else | ||
echo "Failed: redis-cli info replication on master, slave took longer than 10 seconds to show up" | ||
exit 1 | ||
fi | ||
out=$(redis-cli -p 6380 info replication) | ||
|
||
if [[ "$out" =~ "role:slave" ]] | ||
then | ||
echo "Role:slave in redis-cli on replica" | ||
else | ||
echo "Failed: redis-cli info replication on replica" | ||
exit 1 | ||
fi | ||
out=$(redis-cli -p 6380 HMGET "movie:343" title) | ||
if [ "$out" = "Spider-Man" ] | ||
then | ||
echo "redis-cli replicaof done" | ||
else | ||
echo "Failed: redis-cli replication on replica " | ||
exit 1 | ||
fi | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you create a follow up ticket to rework this in the future?, i.e: add an extra check to know the status of the replication (basically, know if the replica is in sync with the master)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created ticket: https://progress.opensuse.org/issues/115592