2018-01-30 11:51:48 +00:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/node"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|