Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move TCL test unit/pubsub to Go case #982

Merged
merged 5 commits into from
Oct 13, 2022
Merged

Conversation

tisonkun
Copy link
Member

This closes #889.

Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
@tisonkun tisonkun merged commit 352dbaf into apache:unstable Oct 13, 2022
@tisonkun tisonkun deleted the move-pubsub branch October 13, 2022 08:15
}, receiveType(t, pubsub, &redis.Subscription{}))

require.EqualValues(t, 0, rdb.Publish(ctx, "chan1", "hello").Val())
require.EqualValues(t, 0, rdb.Publish(ctx, "chan2", "hello").Val())
Copy link
Member Author

@tisonkun tisonkun Oct 13, 2022

Choose a reason for hiding this comment

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

--- FAIL: TestPubSub (1.08s)
    --- FAIL: TestPubSub/PUBLISH/SUBSCRIBE_basics (0.00s)
        pubsub_test.go:76: 
            	Error Trace:	/home/runner/work/incubator-kvrocks/incubator-kvrocks/tests/gocase/unit/pubsub/pubsub_test.go:76
            	Error:      	Not equal: 
            	            	expected: int(0)
            	            	actual  : int64(1)
            	Test:       	TestPubSub/PUBLISH/SUBSCRIBE_basics
    --- FAIL: TestPubSub/PUBLISH/SUBSCRIBE_after_UNSUBSCRIBE_without_arguments (0.00s)
        pubsub_test.go:129: 
            	Error Trace:	/home/runner/work/incubator-kvrocks/incubator-kvrocks/tests/gocase/unit/pubsub/pubsub_test.go:129
            	Error:      	Not equal: 
            	            	expected: int(0)
            	            	actual  : int64(1)
            	Test:       	TestPubSub/PUBLISH/SUBSCRIBE_after_UNSUBSCRIBE_without_arguments

@vmihailenco do you have ideas on this failure? Why can we still publish to a channel even if no one is subscribing to it? It seems like an unstable case instead of a steady one.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

require.EqualValues(t, 2, receiveType(t, pubsub, &redis.Subscription{}).Count)
require.EqualValues(t, 3, receiveType(t, pubsub, &redis.Subscription{}).Count)

require.NoError(t, pubsub.Unsubscribe(ctx))
Copy link

@vmihailenco vmihailenco Oct 13, 2022

Choose a reason for hiding this comment

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

@tisonkun looks like you need to add channels here - "chan1", "chan2", "chan3". Not sure why the test is not failing earlier though and you still receive unsubscribe events... Perhaps some magic by kvrocks when the list of channels is empty? I wonder if Redis behaves the same.

Copy link
Member Author

Choose a reason for hiding this comment

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

@vmihailenco from Redis command docs:

When no channels are specified, the client is unsubscribed from all the previously subscribed channels. In this case, a message for every unsubscribed channel will be sent to the client.

... from go-redis method docs:

// Unsubscribe the client from the given channels, or from all of
// them if none is given.
func (c *PubSub) Unsubscribe(ctx context.Context, channels ...string) error {

So I think this command should behave as "unsubscribe all" otherwise it may be a bug.

The interesting point is that, even we check the unsubscription event happened, we can still publish to those channels. @git-hulk this can be a multi-thread concurrency issue for Kvrocks specifically - I'm unsure about it.

Choose a reason for hiding this comment

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

from go-redis method docs:

Indeed! I honestly can't find where that is implemented and can't check it right away so don't trust it blindly :)

Perhaps it indeed unsubscribes thanks to Redis/kvrocks behavior, but does not reset the internal state of PubSub which can be a cause for surprises.

This comment was marked as resolved.

Copy link
Member Author

Choose a reason for hiding this comment

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

Forgive my comment above, it's about stateful tests.

Choose a reason for hiding this comment

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

You can add defer pubsub.Close() to the tests to properly cleanup pubsub and go-redis should fix redis/go-redis#2248

Copy link
Member Author

@tisonkun tisonkun Oct 13, 2022

Choose a reason for hiding this comment

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

So now I get the point:

Because we don't wait for unsubscription in L76, the "chan2" subscription will never be unsubscribed and leak.

Copy link
Member Author

Choose a reason for hiding this comment

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

We may try to fail fast or reduce share state...But pubsub state are on the server side so the only approach is start a new server for each case?

Copy link
Member Author

Choose a reason for hiding this comment

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

@vmihailenco thank you! Let me think of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move TCL test unit/pubsub to Go case
4 participants