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