Conversation
Signed-off-by: Björn Svensson <[email protected]>
| valkeyReply *reply = create_cluster_slots_reply( | ||
| "[[0, 5460, ['127.0.0.1', 30001, 'e7d1eecce10fd6bb5eb35b9f99a514335d9ba9ca', ['hostname', 'localhost']]," | ||
| " ['127.0.0.1', 30004, '07c37dfeb235213a872192d90877d0cd55635b91', ['hostname', 'localhost']]]," | ||
| " [5461, 10922, ['127.0.0.1', 30002, '67ed2db8d677e59ec4a4cefb06858cf2a1a89fa1', ['hostname', 'localhost']]," |
There was a problem hiding this comment.
Interesting! I guess it's pretty easy to convert this pseudo-JSON to RESP, althought it adds some non-trivial code to the testing. My first though is that single-quoted stings are not allowed in JSON. :)
My second thought is that it might be possible to construct a parse tree structure that is readable and easy to serialize to RESP, without parsing. Ideally, test code should be trivial, so there is no doubt if there's a bug, is it a bug in the test code or in the real implementation?
Here is a reply literal with the first slot range (untested). It's much bigger than the pseudo-JSON obviously.
valkeyReply reply = {.type = VALKEY_REPLY_ARRAY, .elements = 3, .element = (valkeyReply[]){
{.type = VALKEY_REPLY_ARRAY, .elements = 4, .element = (valkeyReply[]){
{.type = VALKEY_REPLY_INTEGER, .integer = 0},
{.type = VALKEY_REPLY_INTEGER, .integer = 5460},
{.type = VALKEY_REPLY_ARRAY, .elements = 4, .element = (valkeyReply[]){
{.type = VALKEY_REPLY_STRING, .str = "127.0.0.1"},
{.type = VALKEY_REPLY_INTEGER, .integer = 30005},
{.type = VALKEY_REPLY_STRING, .str = "e7d1eecce10fd6bb5eb35b9f99a514335d9ba9ca"},
{.type = VALKEY_REPLY_ARRAY, .elements = 2, .element = (valkeyReply[]){
{.type = VALKEY_REPLY_STRING, .str = "hostname"},
{.type = VALKEY_REPLY_STRING, .str = "localhost"}
}
}
},
...
};There was a problem hiding this comment.
Interesting, are there similar tests in the valkey repo?
There was a problem hiding this comment.
No, but similar nested struct literals, in some modules used for module API tests. The one for testing key specifications IIRC.
There was a problem hiding this comment.
The tests for replies like CLUSTER SLOTS use Tcl code which is compact but most often doesn't check the types.
A nested reply like that is a Tcl list on the form
{{0 5460 {127.0.0.1 30001 abcde123456 {hostname localhost} ...
There was a problem hiding this comment.
Hum, I've been trying to get something nicer to work, but have failed so far.
The problem I face is that .element is a valkeyReply **.
Not sure if splitting up the initialization makes it readable, maybe a macro can be used in some way..
There was a problem hiding this comment.
Let's use the pseudo-JSON then. It's pretty simple.
There was a problem hiding this comment.
I'll merge this variant then.
Signed-off-by: Björn Svensson <[email protected]>
Adds
CLUSTER SLOTSparser tests, which uses a testsuite-local primitive parser of a JSON subset to encode arrays to RESP.