mirror of
https://github.com/tendermint/tendermint.git
synced 2026-02-10 22:10:11 +00:00
This is a very small change, but removes a method from the `service.Service` interface (a win!) and forces callers to explicitly pass loggers in to objects during construction rather than (later) injecting them. There's not a real need for this kind of lazy construction of loggers, and I think a decent potential for confusion for mutable loggers. The main concern I have is that this changes the constructor API for ABCI clients. I think this is fine, and I suspect that as we plumb contexts through, and make changes to the RPC services there'll be a number of similar sorts of changes to various (quasi) public interfaces, which I think we should welcome.
95 lines
2.1 KiB
Go
95 lines
2.1 KiB
Go
package proxy
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/mock"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
abciclient "github.com/tendermint/tendermint/abci/client"
|
|
abcimocks "github.com/tendermint/tendermint/abci/client/mocks"
|
|
"github.com/tendermint/tendermint/libs/log"
|
|
)
|
|
|
|
func TestAppConns_Start_Stop(t *testing.T) {
|
|
quitCh := make(<-chan struct{})
|
|
|
|
clientMock := &abcimocks.Client{}
|
|
clientMock.On("Start").Return(nil).Times(4)
|
|
clientMock.On("Stop").Return(nil).Times(4)
|
|
clientMock.On("Quit").Return(quitCh).Times(4)
|
|
|
|
creatorCallCount := 0
|
|
creator := func(logger log.Logger) (abciclient.Client, error) {
|
|
creatorCallCount++
|
|
return clientMock, nil
|
|
}
|
|
|
|
appConns := NewAppConns(creator, log.TestingLogger(), NopMetrics())
|
|
|
|
err := appConns.Start()
|
|
require.NoError(t, err)
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
err = appConns.Stop()
|
|
require.NoError(t, err)
|
|
|
|
clientMock.AssertExpectations(t)
|
|
assert.Equal(t, 4, creatorCallCount)
|
|
}
|
|
|
|
// Upon failure, we call tmos.Kill
|
|
func TestAppConns_Failure(t *testing.T) {
|
|
ok := make(chan struct{})
|
|
c := make(chan os.Signal, 1)
|
|
signal.Notify(c, syscall.SIGTERM)
|
|
go func() {
|
|
for range c {
|
|
close(ok)
|
|
}
|
|
}()
|
|
|
|
quitCh := make(chan struct{})
|
|
var recvQuitCh <-chan struct{} // nolint:gosimple
|
|
recvQuitCh = quitCh
|
|
|
|
clientMock := &abcimocks.Client{}
|
|
clientMock.On("SetLogger", mock.Anything).Return()
|
|
clientMock.On("Start").Return(nil)
|
|
clientMock.On("Stop").Return(nil)
|
|
|
|
clientMock.On("Quit").Return(recvQuitCh)
|
|
clientMock.On("Error").Return(errors.New("EOF")).Once()
|
|
|
|
creator := func(log.Logger) (abciclient.Client, error) {
|
|
return clientMock, nil
|
|
}
|
|
|
|
appConns := NewAppConns(creator, log.TestingLogger(), NopMetrics())
|
|
|
|
err := appConns.Start()
|
|
require.NoError(t, err)
|
|
t.Cleanup(func() {
|
|
if err := appConns.Stop(); err != nil {
|
|
t.Error(err)
|
|
}
|
|
})
|
|
|
|
// simulate failure
|
|
close(quitCh)
|
|
|
|
select {
|
|
case <-ok:
|
|
t.Log("SIGTERM successfully received")
|
|
case <-time.After(5 * time.Second):
|
|
t.Fatal("expected process to receive SIGTERM signal")
|
|
}
|
|
}
|