status-go/metrics/node/subscribe_test.go

39 lines
827 B
Go
Raw Normal View History

package node
import (
"context"
"testing"
"github.com/stretchr/testify/require"
2020-01-02 09:10:19 +00:00
"github.com/ethereum/go-ethereum/node"
)
func TestSubscribeServerEventsWithoutServer(t *testing.T) {
2019-02-01 17:02:52 +00:00
gethNode, err := node.New(&node.Config{NoUSB: true})
require.NoError(t, err)
require.EqualError(t, SubscribeServerEvents(context.TODO(), gethNode), "server is unavailable")
}
func TestSubscribeServerEvents(t *testing.T) {
2019-02-01 17:02:52 +00:00
gethNode, err := node.New(&node.Config{NoUSB: true})
require.NoError(t, err)
err = gethNode.Start()
require.NoError(t, err)
defer func() {
err := gethNode.Stop()
require.NoError(t, err)
}()
ctx, cancel := context.WithCancel(context.Background())
done := make(chan struct{})
go func() {
err := SubscribeServerEvents(ctx, gethNode)
require.NoError(t, err)
close(done)
}()
cancel()
<-done
}