Skip to content

Add test to cover NAN reply using a module#11482

Merged
oranagra merged 2 commits intoredis:unstablefrom
oranagra:nan_reply
Nov 13, 2022
Merged

Add test to cover NAN reply using a module#11482
oranagra merged 2 commits intoredis:unstablefrom
oranagra:nan_reply

Conversation

@oranagra
Copy link
Member

@oranagra oranagra commented Nov 7, 2022

Adding a test to cover the already existing behavior of NAN replies, to accompany the PR that adds them to the RESP3 spec: redis/redis-specifications#10

This PR also covers Inf replies that are already in the spec, as well as RESP2 coverage.

@oranagra
Copy link
Member Author

oranagra commented Nov 7, 2022

For some reason that's not yet clear to me, the reply i get is -nan (not nan as the spec in the PR, and examples in the related issue)

@oranagra oranagra added the state:major-decision Requires core team consensus label Nov 7, 2022
Comment on lines +43 to +44
assert_equal "-nan" [r rw.double 0 0]
assert_equal "nan" [r rw.double]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Negative NaN??? What is that...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apparently that's what you get from redis (or actually both glibc and the alternative we added in #10587).
so either we "fix" it with a breaking change, or document it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine then. Apparently the sign bit in a NaN is usually ignored but not always... Wikipedia:

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh, now i see the Negative NaN also break ours extra-cli
https://github.com/redis/redis-extra-ci/actions/runs/3457946091/jobs/5771873230#step:8:846

*** [err]: RESP2: RM_ReplyWithDouble: NaN in tests/unit/moduleapi/reply.tcl
Expected '-nan' to be equal to 'nan' (context: type eval line 3 cmd {assert_equal "-nan" [r rw.double 0 0]} proc ::test)
*** [err]: RESP3: RM_ReplyWithDouble: NaN in tests/unit/moduleapi/reply.tcl
Expected ',-nan' to be equal to ',nan' (context: type eval line 8 cmd {assert_equal ",-nan" [r rw.double 0 0]} proc ::test)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm careless.. i should have tested this on Mac and ARM before merging.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's do pattern matching to search any kind of nan, ignoring character case and sign.
@enjoy-binbin can you make a PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make a quick PR: #11506

Copy link
Contributor

@zuiderkwast zuiderkwast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@oranagra oranagra requested a review from yossigo November 9, 2022 08:28
@oranagra
Copy link
Member Author

oranagra commented Nov 9, 2022

PR was approved in a core-team meeting (keeping both positive and negative NaN).

@oranagra oranagra merged commit 78dc292 into redis:unstable Nov 13, 2022
@oranagra oranagra deleted the nan_reply branch November 13, 2022 11:12
assert_equal "-inf" [r rw.double -inf]
} else {
assert_equal Inf [r rw.double inf]
assert_equal -Inf [r rw.double -inf]
Copy link
Contributor

@enjoy-binbin enjoy-binbin Nov 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/redis/redis/actions/runs/3457509357/jobs/5770995313#step:6:906
look like this one is not the same on mac

*** [err]: RESP3: RM_ReplyWithDouble: inf in tests/unit/moduleapi/reply.tcl
Expected 'Inf' to be equal to 'inf' (context: type eval line 6 cmd {assert_equal Inf [r rw.double inf]} proc ::test)

ok, i see this will work, i am making the PR: #11504
https://github.com/enjoy-binbin/redis/actions/runs/3458050562/jobs/5772080570#step:6:608

                # TCL convert inf to different results on different platforms, e.g. inf on mac
                # and Inf on others, so use readraw to verify the protocol
                r readraw 1
                assert_equal ",inf" [r rw.double inf]
                assert_equal ",-inf" [r rw.double -inf]
                r readraw 0

enjoy-binbin added a commit to enjoy-binbin/redis that referenced this pull request Nov 14, 2022
The test introduced in redis#11482 fail on mac:
```
*** [err]: RESP3: RM_ReplyWithDouble: inf in tests/unit/moduleapi/reply.tcl
Expected 'Inf' to be equal to 'inf'
(context: type eval line 6 cmd {assert_equal Inf [r rw.double inf]} proc ::test)
```

Looks like the mac platform returns inf instead of Inf in this case, this PR
uses readraw to verify the protocol.
oranagra pushed a commit that referenced this pull request Nov 14, 2022
The test introduced in #11482 fail on mac:
```
*** [err]: RESP3: RM_ReplyWithDouble: inf in tests/unit/moduleapi/reply.tcl
Expected 'Inf' to be equal to 'inf'
(context: type eval line 6 cmd {assert_equal Inf [r rw.double inf]} proc ::test)
```

Looks like the mac platform returns inf instead of Inf in this case, this PR
uses readraw to verify the protocol.
enjoy-binbin added a commit to enjoy-binbin/redis that referenced this pull request Nov 14, 2022
The test introduced in redis#11482 fail on ARM (extra CI):
```
*** [err]: RESP2: RM_ReplyWithDouble: NaN in tests/unit/moduleapi/reply.tcl
Expected '-nan' to be equal to 'nan' (context: type eval line 3 cmd
{assert_equal "-nan" [r rw.double 0 0]} proc ::test)

*** [err]: RESP3: RM_ReplyWithDouble: NaN in tests/unit/moduleapi/reply.tcl
Expected ',-nan' to be equal to ',nan' (context: type eval line 8 cmd
{assert_equal ",-nan" [r rw.double 0 0]} proc ::test)
```

It looks like there is no nagative nan on ARM. In this PR, we add a new
`assert_match_nocase` to do the matching, ignoring case and sign.
oranagra pushed a commit that referenced this pull request Nov 15, 2022
The test introduced in #11482 fail on ARM (extra CI):
```
*** [err]: RESP2: RM_ReplyWithDouble: NaN in tests/unit/moduleapi/reply.tcl
Expected '-nan' to be equal to 'nan' (context: type eval line 3 cmd
{assert_equal "-nan" [r rw.double 0 0]} proc ::test)

*** [err]: RESP3: RM_ReplyWithDouble: NaN in tests/unit/moduleapi/reply.tcl
Expected ',-nan' to be equal to ',nan' (context: type eval line 8 cmd
{assert_equal ",-nan" [r rw.double 0 0]} proc ::test)
```

It looks like there is no negative nan on ARM.
@oranagra
Copy link
Member Author

@yossigo @madolson PTAL
if i read https://en.wikipedia.org/wiki/NaN#Display correctly, it says that apart from nan and -nan we can also get NAN and even nan(char-sequence) from libc.
so if we keep the current code and pass that directly to the protocol, we need to update the spec.
i.e. we avoid any compatibility changes across redis versions and shift that problem to the client.

personally, i think we better normalize it by calling isnan() and create a single nan form in the protocol.
please respond.

@enjoy-binbin
Copy link
Contributor

according to the comments above, just for test, i made this change: 2614b68

btw, in this case, i guess we need to revert the assert_match part in #11506, use assert_equal just like inf test

module test passed in local and triggered a full daily CI to see: https://github.com/enjoy-binbin/redis/actions/runs/3529145166

@madolson
Copy link
Contributor

@oranagra I thought the point was that we still needed to document that for compatibility other values of nan might be returned. I have no problem with normalizing the changes moving forward.

@zuiderkwast
Copy link
Contributor

Normalizing seems better considering we already normalize inf:

void addReplyDouble(client *c, double d) {
    if (isinf(d)) {
        /* Libc in odd systems (Hi Solaris!) will format infinite in a
         * different way, so better to handle it in an explicit way. */
        if (c->resp == 2) {
            addReplyBulkCString(c, d > 0 ? "inf" : "-inf");
        } else {
            addReplyProto(c, d > 0 ? ",inf\r\n" : ",-inf\r\n",
                              d > 0 ? 6 : 7);
        }

@oranagra
Copy link
Member Author

oranagra commented Dec 8, 2022

We discussed this again in a core-team meeting.
our conclusion was that we wanna normalize it in redis to a single nan type, and maybe also document the other types (specifically the negative one) in the protocol as a backwards compatibility thing.

enjoy-binbin added a commit to enjoy-binbin/redis that referenced this pull request Dec 8, 2022
From https://en.wikipedia.org/wiki/NaN#Display, it says
that apart from nan and -nan, we can also get NAN and even
nan(char-sequence) from libc.

In redis#11482, our conclusion was that we wanna normalize it in
Redis to a single nan type, like we already normalized inf.

For this, we also reverted the assert_match part of the test
added in redis#11506, using assert_equal to validate the changes.
oranagra pushed a commit that referenced this pull request Dec 8, 2022
From https://en.wikipedia.org/wiki/NaN#Display, it says
that apart from nan and -nan, we can also get NAN and even
nan(char-sequence) from libc.

In #11482, our conclusion was that we wanna normalize it in
Redis to a single nan type, like we already normalized inf.

For this, we also reverted the assert_match part of the test
added in #11506, using assert_equal to validate the changes.
@oranagra
Copy link
Member Author

oranagra commented Dec 8, 2022

ok, redis fixed, someone wanna attempt to have a go at the RESP spec or redis-doc (i didn't bother to check what's the scope)

@enjoy-binbin
Copy link
Contributor

RESP spec: redis/redis-specifications#11

madolson pushed a commit to madolson/redis that referenced this pull request Apr 19, 2023
Adding a test to cover the already existing behavior of NAN replies,
to accompany the PR that adds them to the RESP3 spec:
redis/redis-specifications#10

This PR also covers Inf replies that are already in the spec, as well as RESP2 coverage.
madolson pushed a commit to madolson/redis that referenced this pull request Apr 19, 2023
The test introduced in redis#11482 fail on mac:
```
*** [err]: RESP3: RM_ReplyWithDouble: inf in tests/unit/moduleapi/reply.tcl
Expected 'Inf' to be equal to 'inf'
(context: type eval line 6 cmd {assert_equal Inf [r rw.double inf]} proc ::test)
```

Looks like the mac platform returns inf instead of Inf in this case, this PR
uses readraw to verify the protocol.
madolson pushed a commit to madolson/redis that referenced this pull request Apr 19, 2023
The test introduced in redis#11482 fail on ARM (extra CI):
```
*** [err]: RESP2: RM_ReplyWithDouble: NaN in tests/unit/moduleapi/reply.tcl
Expected '-nan' to be equal to 'nan' (context: type eval line 3 cmd
{assert_equal "-nan" [r rw.double 0 0]} proc ::test)

*** [err]: RESP3: RM_ReplyWithDouble: NaN in tests/unit/moduleapi/reply.tcl
Expected ',-nan' to be equal to ',nan' (context: type eval line 8 cmd
{assert_equal ",-nan" [r rw.double 0 0]} proc ::test)
```

It looks like there is no negative nan on ARM.
madolson pushed a commit to madolson/redis that referenced this pull request Apr 19, 2023
From https://en.wikipedia.org/wiki/NaN#Display, it says
that apart from nan and -nan, we can also get NAN and even
nan(char-sequence) from libc.

In redis#11482, our conclusion was that we wanna normalize it in
Redis to a single nan type, like we already normalized inf.

For this, we also reverted the assert_match part of the test
added in redis#11506, using assert_equal to validate the changes.
enjoy-binbin pushed a commit to enjoy-binbin/redis that referenced this pull request Jul 31, 2023
Adding a test to cover the already existing behavior of NAN replies,
to accompany the PR that adds them to the RESP3 spec:
redis/redis-specifications#10

This PR also covers Inf replies that are already in the spec, as well as RESP2 coverage.
enjoy-binbin added a commit to enjoy-binbin/redis that referenced this pull request Jul 31, 2023
The test introduced in redis#11482 fail on mac:
```
*** [err]: RESP3: RM_ReplyWithDouble: inf in tests/unit/moduleapi/reply.tcl
Expected 'Inf' to be equal to 'inf'
(context: type eval line 6 cmd {assert_equal Inf [r rw.double inf]} proc ::test)
```

Looks like the mac platform returns inf instead of Inf in this case, this PR
uses readraw to verify the protocol.
enjoy-binbin added a commit to enjoy-binbin/redis that referenced this pull request Jul 31, 2023
The test introduced in redis#11482 fail on ARM (extra CI):
```
*** [err]: RESP2: RM_ReplyWithDouble: NaN in tests/unit/moduleapi/reply.tcl
Expected '-nan' to be equal to 'nan' (context: type eval line 3 cmd
{assert_equal "-nan" [r rw.double 0 0]} proc ::test)

*** [err]: RESP3: RM_ReplyWithDouble: NaN in tests/unit/moduleapi/reply.tcl
Expected ',-nan' to be equal to ',nan' (context: type eval line 8 cmd
{assert_equal ",-nan" [r rw.double 0 0]} proc ::test)
```

It looks like there is no negative nan on ARM.
enjoy-binbin added a commit to enjoy-binbin/redis that referenced this pull request Jul 31, 2023
From https://en.wikipedia.org/wiki/NaN#Display, it says
that apart from nan and -nan, we can also get NAN and even
nan(char-sequence) from libc.

In redis#11482, our conclusion was that we wanna normalize it in
Redis to a single nan type, like we already normalized inf.

For this, we also reverted the assert_match part of the test
added in redis#11506, using assert_equal to validate the changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state:major-decision Requires core team consensus

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants