mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-10 06:57:24 +00:00
This is part of the work described by #7156. Remove "unbuffered subscriptions" from the pubsub service. Replace them with a dedicated blocking "observer" mechanism. Use the observer mechanism for indexing. Add a SubscribeWithArgs method and deprecate the old Subscribe method. Remove SubscribeUnbuffered entirely (breaking). Rework the Subscription interface to eliminate exposed channels. Subscriptions now use a context to manage lifecycle notifications. Internalize the eventbus package.
32 lines
743 B
Go
32 lines
743 B
Go
package pubsub_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
"github.com/tendermint/tendermint/libs/pubsub"
|
|
"github.com/tendermint/tendermint/libs/pubsub/query"
|
|
)
|
|
|
|
func TestExample(t *testing.T) {
|
|
s := newTestServer(t)
|
|
ctx := context.Background()
|
|
|
|
sub := newTestSub(t).must(s.SubscribeWithArgs(ctx, pubsub.SubscribeArgs{
|
|
ClientID: "example-client",
|
|
Query: query.MustParse("abci.account.name='John'"),
|
|
}))
|
|
|
|
events := []abci.Event{
|
|
{
|
|
Type: "abci.account",
|
|
Attributes: []abci.EventAttribute{{Key: "name", Value: "John"}},
|
|
},
|
|
}
|
|
require.NoError(t, s.PublishWithEvents(ctx, "Tombstone", events))
|
|
sub.mustReceive(ctx, "Tombstone")
|
|
}
|