Skip to content

Commit

Permalink
Enhance the redis test to know the status of the replication
Browse files Browse the repository at this point in the history
  • Loading branch information
pdostal committed Sep 13, 2022
1 parent 456acff commit e839895
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 102 deletions.
80 changes: 0 additions & 80 deletions data/console/redis_cli.sh

This file was deleted.

58 changes: 36 additions & 22 deletions tests/console/redis.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ use base 'consoletest';
use strict;
use warnings;
use testapi;
use utils 'zypper_call';
use version_utils;
use utils qw(zypper_call script_retry validate_script_output_retry);
use registration qw(add_suseconnect_product get_addon_fullname);

sub run {
Expand All @@ -26,22 +25,39 @@ sub run {

# install redis package
zypper_call 'in redis';
assert_script_run('redis-server --version');

# start redis server on port 6379 and test that it works
assert_script_run('redis-server --daemonize yes --logfile /var/log/redis/redis-server_6379.log');
script_retry('redis-cli ping', delay => 5, retry => 12);
validate_script_output_retry('redis-cli ping', sub { m/PONG/ }, delay => 5, retry => 12);

# test some redis cli commands
validate_script_output('redis-cli set foo bar', sub { m/OK/ });
validate_script_output('redis-cli get foo', sub { m/bar/ });
validate_script_output('redis-cli pfselftest', sub { m/OK/ });
validate_script_output('redis-cli flushdb', sub { m/OK/ });
validate_script_output('redis-cli get foo', sub { m/(nil)/ });

# start redis server on port 6379 and 6380
background_script_run('redis-server');
wait_still_screen(5);
background_script_run('redis-server --port 6380');
wait_still_screen(5);
assert_script_run 'curl -O ' . data_url('console/movies.redis');
run_script('redis_cli.sh');
}
assert_script_run('redis-cli -h localhost -p 6379 < ./movies.redis');

validate_script_output('redis-cli HMGET "movie:343" title', sub { m/Spider-Man/ });

# start redis server on port 6380 and test that it works
assert_script_run('redis-server --daemonize yes --port 6380 --logfile /var/log/redis/redis-server_6380.log');
validate_script_output_retry('redis-cli -p 6380 ping', sub { m/PONG/ }, delay => 5, retry => 12);

# make 6380 instance a replica of redis instance running on port 6379
assert_script_run('redis-cli -p 6380 replicaof localhost 6379');

# test master knows about the slave and vice versa
validate_script_output_retry('redis-cli info replication', sub { m/connected_slaves:1/ }, delay => 5, retry => 12);
validate_script_output('redis-cli -p 6380 info replication', sub { m/role:slave/ });

sub run_script {
my $script = shift;
record_info($script, "Running shell script: $script");
assert_script_run("curl " . data_url("console/$script") . " -o '$script'");
assert_script_run("chmod a+rx '$script'");
assert_script_run("./$script");
# test that the synchronization finished and the data are reachable from slave
validate_script_output_retry('redis-cli info replication', sub { m/state=online/ }, delay => 5, retry => 12);
validate_script_output('redis-cli -p 6380 HMGET "movie:343" title', sub { m/Spider-Man/ });
}

sub post_fail_hook {
Expand All @@ -57,13 +73,11 @@ sub post_run_hook {
}

sub cleanup {
script_run('redis-cli -h localhost flushall');
wait_still_screen(5);
script_run('killall redis-server');
wait_still_screen(5);
script_run('rm -f movies.redis');
wait_still_screen(5);
script_run('rm -f redis_cli.sh');
upload_logs('/var/log/redis/redis-server_6379.log');
upload_logs('/var/log/redis/redis-server_6380.log');
assert_script_run('redis-cli -h localhost flushall');
assert_script_run('killall redis-server');
assert_script_run('rm -f movies.redis');
}

1;

0 comments on commit e839895

Please sign in to comment.