mirror of
https://github.com/hanzoai/kv.git
synced 2026-11-09 16:05:35 +00:00
`merge: upstream/unstable (-X ours, brand preserved)` resolved every conflicting
hunk in our favour. That is right for brand strings and wrong for code: it kept
our old server.h beside their new module.c, so module.c calls
commandResultSuccessListeners and reads from_call_argv off a struct that has
neither, and zslFreeLexRange lost the declarations it still has call sites for.
kvReaderFeed got a newer body calling kvReaderGetReadBuf/CommitRead grafted onto
older locals — an sds newbuf and an oom: label the new body never uses. Across
398 files nothing downstream noticed, because main has not compiled since.
That is what the Dockerfile was working around. Pulling valkey/valkey and copying
binaries out of it produced an image no matter what the source did, so a tree
that cannot build looked like a tree that builds. Now the image compiles this
source, so the build breaking is visible the moment it breaks.
src, deps and tests return to the last coherent commit. Carried forward on top:
- Two identical rdbIsVersionAccepted definitions, differing only in a
parameter name. The rename pass copied the function instead of editing it,
so this never compiled either.
- kv_strtod.h lost the #ifdef USE_FAST_FLOAT that separated its two
implementations, leaving both definitions and a stray #endif.
- extended-redis-compatibility is deleted, not defaulted off. It made the
server answer HELLO with "redis" and name itself Redis in five error
strings. A server that can be configured to lie about what it is has one
setting too many. HELLO now reports kv unconditionally.
- The redis-server and redis-cli install symlinks, on by default via
USE_REDIS_SYMLINKS?=yes. This is why a running instance answered to
redis-cli at all.
- valkeymodule.h and redismodule.h, 3094 lines of adapters mapping old
prefixes onto KVMODULE_*, included by nothing. kvmodule.h is the header.
- deps/libvalkey, one documentation file the rename stranded.
Wire contract is untouched. INFO still reports redis_version, redis_git_sha1,
redis_git_dirty and redis_build_id, and the Lua sandbox still exports
REDIS_VERSION — clients parse those field names, so they are protocol, not
branding. What we choose is what the server calls itself, and it calls itself kv.
Verified: builds clean, and a live instance answers HELLO with "server kv",
reports server_name:kv, has no extended-redis-compatibility directive, and
serves strings and lists.
205 lines
6.6 KiB
C
205 lines
6.6 KiB
C
/* Some unit tests that don't require KV to be running. */
|
|
|
|
#include "fmacros.h"
|
|
#include "win32.h"
|
|
|
|
#include "cluster.h"
|
|
#include "command.h"
|
|
#include "test_utils.h"
|
|
|
|
#include <assert.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
/* Helper for the macro ASSERT_KEY below. */
|
|
void check_key(const char *key, struct cmd *command, const char *file, int line) {
|
|
if (command->result != CMD_PARSE_OK) {
|
|
fprintf(stderr, "%s:%d: Command parsing failed: %s\n", file, line,
|
|
command->errstr);
|
|
assert(0);
|
|
}
|
|
char *actual_key = command->key.start;
|
|
int actual_keylen = command->key.len;
|
|
if ((int)strlen(key) != actual_keylen ||
|
|
strncmp(key, actual_key, actual_keylen)) {
|
|
fprintf(stderr,
|
|
"%s:%d: Expected key to be \"%s\" but got \"%.*s\"\n",
|
|
file, line, key, actual_keylen, actual_key);
|
|
assert(0);
|
|
}
|
|
}
|
|
|
|
/* Checks that a command (struct cmd *) has the given key (string). */
|
|
#define ASSERT_KEY(command, key) \
|
|
do { \
|
|
check_key(key, command, __FILE__, __LINE__); \
|
|
} while (0)
|
|
|
|
void test_kv_parse_error_nonresp(void) {
|
|
struct cmd *c = command_get();
|
|
c->cmd = strdup("+++Not RESP+++\r\n");
|
|
c->clen = strlen(c->cmd);
|
|
|
|
kv_parse_cmd(c);
|
|
ASSERT_MSG(c->result == CMD_PARSE_ERROR, "Unexpected parse success");
|
|
ASSERT_MSG(!strcmp(c->errstr, "Command parse error"), c->errstr);
|
|
command_destroy(c);
|
|
}
|
|
|
|
void test_kv_parse_cmd_get(void) {
|
|
struct cmd *c = command_get();
|
|
int len = kvFormatCommand(&c->cmd, "GET foo");
|
|
ASSERT_MSG(len >= 0, "Format command error");
|
|
c->clen = len;
|
|
kv_parse_cmd(c);
|
|
ASSERT_MSG(c->result == CMD_PARSE_OK, "Parse not OK");
|
|
ASSERT_KEY(c, "foo");
|
|
command_destroy(c);
|
|
}
|
|
|
|
void test_kv_parse_cmd_mset(void) {
|
|
struct cmd *c = command_get();
|
|
int len = kvFormatCommand(&c->cmd, "MSET foo val1 bar val2");
|
|
ASSERT_MSG(len >= 0, "Format command error");
|
|
c->clen = len;
|
|
kv_parse_cmd(c);
|
|
ASSERT_MSG(c->result == CMD_PARSE_OK, "Parse not OK");
|
|
ASSERT_KEY(c, "foo");
|
|
command_destroy(c);
|
|
}
|
|
|
|
void test_kv_parse_cmd_eval_1(void) {
|
|
struct cmd *c = command_get();
|
|
int len = kvFormatCommand(&c->cmd, "EVAL dummyscript 1 foo");
|
|
ASSERT_MSG(len >= 0, "Format command error");
|
|
c->clen = len;
|
|
kv_parse_cmd(c);
|
|
ASSERT_MSG(c->result == CMD_PARSE_OK, "Parse not OK");
|
|
ASSERT_KEY(c, "foo");
|
|
command_destroy(c);
|
|
}
|
|
|
|
void test_kv_parse_cmd_eval_0(void) {
|
|
struct cmd *c = command_get();
|
|
int len = kvFormatCommand(&c->cmd, "EVAL dummyscript 0 foo");
|
|
ASSERT_MSG(len >= 0, "Format command error");
|
|
c->clen = len;
|
|
kv_parse_cmd(c);
|
|
ASSERT_MSG(c->result == CMD_PARSE_OK, "Parse not OK");
|
|
ASSERT_MSG(c->key.len == 0, "Unexpected key found");
|
|
command_destroy(c);
|
|
}
|
|
|
|
void test_kv_parse_cmd_xgroup_no_subcommand(void) {
|
|
struct cmd *c = command_get();
|
|
int len = kvFormatCommand(&c->cmd, "XGROUP");
|
|
ASSERT_MSG(len >= 0, "Format command error");
|
|
c->clen = len;
|
|
kv_parse_cmd(c);
|
|
ASSERT_MSG(c->result == CMD_PARSE_ERROR, "Unexpected parse success");
|
|
ASSERT_MSG(!strcmp(c->errstr, "Unknown command XGROUP"), c->errstr);
|
|
command_destroy(c);
|
|
}
|
|
|
|
void test_kv_parse_cmd_xgroup_destroy_no_key(void) {
|
|
struct cmd *c = command_get();
|
|
int len = kvFormatCommand(&c->cmd, "xgroup destroy");
|
|
ASSERT_MSG(len >= 0, "Format command error");
|
|
c->clen = len;
|
|
kv_parse_cmd(c);
|
|
ASSERT_MSG(c->result == CMD_PARSE_ERROR, "Parse not OK");
|
|
const char *expected_error =
|
|
"Failed to find keys of command XGROUP DESTROY";
|
|
ASSERT_MSG(!strncmp(c->errstr, expected_error, strlen(expected_error)),
|
|
c->errstr);
|
|
command_destroy(c);
|
|
}
|
|
|
|
void test_kv_parse_cmd_xgroup_destroy_ok(void) {
|
|
struct cmd *c = command_get();
|
|
int len = kvFormatCommand(&c->cmd, "xgroup destroy mystream mygroup");
|
|
ASSERT_MSG(len >= 0, "Format command error");
|
|
c->clen = len;
|
|
kv_parse_cmd(c);
|
|
ASSERT_KEY(c, "mystream");
|
|
command_destroy(c);
|
|
}
|
|
|
|
void test_kv_parse_cmd_xreadgroup_ok(void) {
|
|
struct cmd *c = command_get();
|
|
/* Use group name and consumer name "streams" just to try to confuse the
|
|
* parser. The parser shouldn't mistake those for the STREAMS keyword. */
|
|
int len = kvFormatCommand(
|
|
&c->cmd, "XREADGROUP GROUP streams streams COUNT 1 streams mystream >");
|
|
ASSERT_MSG(len >= 0, "Format command error");
|
|
c->clen = len;
|
|
kv_parse_cmd(c);
|
|
ASSERT_KEY(c, "mystream");
|
|
command_destroy(c);
|
|
}
|
|
|
|
void test_kv_parse_cmd_xread_ok(void) {
|
|
struct cmd *c = command_get();
|
|
int len = kvFormatCommand(
|
|
&c->cmd, "XREAD BLOCK 42 STREAMS mystream another $ $");
|
|
ASSERT_MSG(len >= 0, "Format command error");
|
|
c->clen = len;
|
|
kv_parse_cmd(c);
|
|
ASSERT_KEY(c, "mystream");
|
|
command_destroy(c);
|
|
}
|
|
|
|
void test_kv_parse_cmd_restore_ok(void) {
|
|
/* The ordering of RESTORE and RESTORE-ASKING in the lookup-table was wrong
|
|
* in a previous version, leading to the command not being found. */
|
|
struct cmd *c = command_get();
|
|
int len = kvFormatCommand(&c->cmd, "restore k 0 xxx");
|
|
ASSERT_MSG(len >= 0, "Format command error");
|
|
c->clen = len;
|
|
kv_parse_cmd(c);
|
|
ASSERT_KEY(c, "k");
|
|
command_destroy(c);
|
|
}
|
|
|
|
void test_kv_parse_cmd_restore_asking_ok(void) {
|
|
/* The ordering of RESTORE and RESTORE-ASKING in the lookup-table was wrong
|
|
* in a previous version, leading to the command not being found. */
|
|
struct cmd *c = command_get();
|
|
int len = kvFormatCommand(&c->cmd, "restore-asking k 0 xxx");
|
|
ASSERT_MSG(len >= 0, "Format command error");
|
|
c->clen = len;
|
|
kv_parse_cmd(c);
|
|
ASSERT_KEY(c, "k");
|
|
command_destroy(c);
|
|
}
|
|
|
|
void test_kv_parse_cmd_georadius_ro_ok(void) {
|
|
/* The position of GEORADIUS_RO was wrong in a previous version of the
|
|
* lookup-table, leading to the command not being found. */
|
|
struct cmd *c = command_get();
|
|
int len = kvFormatCommand(&c->cmd, "georadius_ro k 0 0 0 km");
|
|
ASSERT_MSG(len >= 0, "Format command error");
|
|
c->clen = len;
|
|
kv_parse_cmd(c);
|
|
ASSERT_KEY(c, "k");
|
|
command_destroy(c);
|
|
}
|
|
|
|
int main(void) {
|
|
test_kv_parse_error_nonresp();
|
|
test_kv_parse_cmd_get();
|
|
test_kv_parse_cmd_mset();
|
|
test_kv_parse_cmd_eval_1();
|
|
test_kv_parse_cmd_eval_0();
|
|
test_kv_parse_cmd_xgroup_no_subcommand();
|
|
test_kv_parse_cmd_xgroup_destroy_no_key();
|
|
test_kv_parse_cmd_xgroup_destroy_ok();
|
|
test_kv_parse_cmd_xreadgroup_ok();
|
|
test_kv_parse_cmd_xread_ok();
|
|
test_kv_parse_cmd_restore_ok();
|
|
test_kv_parse_cmd_restore_asking_ok();
|
|
test_kv_parse_cmd_georadius_ro_ok();
|
|
return 0;
|
|
}
|