Skip to content

Commit

Permalink
Made it possible to run test/test_redis++ in parallel. (sewenew#236)
Browse files Browse the repository at this point in the history
Remove script flush related test, and add user-defined key prefix support.
  • Loading branch information
wingunder authored May 28, 2021
1 parent 6bba7dc commit 80d44fd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2061,7 +2061,7 @@ You can publish and subscribe messages with `RedisCluster`. The interfaces are e
You can also create `Pipeline` and `Transaction` objects with `RedisCluster`, but the interfaces are different from `Redis`. Since all commands in the pipeline and transaction should be sent to a single node in a single connection, we need to tell `RedisCluster` with which node the pipeline or transaction should be created.
Instead of specifing the node's IP and port, `RedisCluster`'s pipeline and transaction interfaces allow you to specify the node with a *hash tag*. `RedisCluster` will calculate the slot number with the given *hash tag*, and create a pipeline or transaction with the node holding the slot.
Instead of specifying the node's IP and port, `RedisCluster`'s pipeline and transaction interfaces allow you to specify the node with a *hash tag*. `RedisCluster` will calculate the slot number with the given *hash tag*, and create a pipeline or transaction with the node holding the slot.
```C++
Pipeline RedisCluster::pipeline(const StringView &hash_tag, bool new_connection = true);
Expand Down
6 changes: 0 additions & 6 deletions test/src/sw/redis++/script_cmds_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@ void ScriptCmdTest<RedisInstance>::_run(Redis &instance) {

REDIS_ASSERT(instance.script_exists(sha1), "failed to test script exists");
REDIS_ASSERT(!instance.script_exists("not exist"), "failed to test script exists");

instance.script_flush();
exist_res.clear();
instance.script_exists({sha1, sha2, std::string("not exist")}, std::back_inserter(exist_res));
REDIS_ASSERT(exist_res == std::list<bool>({false, false, false}),
"failed to test script flush");
}

}
Expand Down
10 changes: 7 additions & 3 deletions test/src/sw/redis++/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ int getopt(int argc, char **argv, const char *optstring) {

void print_help() {
std::cerr << "Usage: test_redis++ -h host -p port"
<< " -n cluster_node -c cluster_port [-a auth] [-b]\n\n";
<< " -n cluster_node -c cluster_port [-a auth] [-b] [-e key_prefix]\n\n";
std::cerr << "See https://github.com/sewenew/redis-plus-plus#run-tests-optional"
<< " for details on how to run test" << std::endl;
}
Expand All @@ -232,7 +232,7 @@ auto parse_options(int argc, char **argv)
TestOptions test_options;

int opt = 0;
while ((opt = getopt(argc, argv, "h:p:a:n:c:k:v:r:t:bs:m")) != -1) {
while ((opt = getopt(argc, argv, "h:p:a:n:c:e:k:v:r:t:bs:m")) != -1) {
try {
switch (opt) {
case 'h':
Expand Down Expand Up @@ -283,8 +283,12 @@ auto parse_options(int argc, char **argv)
test_options.run_thread_test = true;
break;

case 'e':
sw::redis::test::key_prefix(optarg);
break;

default:
throw sw::redis::Error("Unknow command line option");
throw sw::redis::Error("Unknown command line option");
break;
}
} catch (const sw::redis::Error &e) {
Expand Down
11 changes: 10 additions & 1 deletion test/src/sw/redis++/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,19 @@ inline void redis_assert(bool condition,
}
}

inline std::string key_prefix(const std::string &key = "") {
static std::string KEY_PREFIX = "sw::redis::test";
if (!key.empty()) {
KEY_PREFIX = key;
}

return KEY_PREFIX;
}

inline std::string test_key(const std::string &k) {
// Key prefix with hash tag,
// so that we can call multiple-key commands on RedisCluster.
return "{sw::redis::test}::" + k;
return "{" + key_prefix() + "}::" + k;
}

template <typename Test>
Expand Down

0 comments on commit 80d44fd

Please sign in to comment.