Some checks are pending
docker-build-cometbft / vars (push) Waiting to run
docker-build-cometbft / build-images (amd64, ubuntu-24.04) (push) Blocked by required conditions
docker-build-cometbft / build-images (arm64, ubuntu-24.04-arm) (push) Blocked by required conditions
docker-build-cometbft / merge-images (push) Blocked by required conditions
docker-build-e2e-node / vars (push) Waiting to run
docker-build-e2e-node / build-images (amd64, ubuntu-24.04) (push) Blocked by required conditions
docker-build-e2e-node / build-images (arm64, ubuntu-24.04-arm) (push) Blocked by required conditions
docker-build-e2e-node / merge-images (push) Blocked by required conditions
89 lines
2 KiB
Go
89 lines
2 KiB
Go
package proxy
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/mock"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
abcimocks "git.cw.tr/mukan-network/mukan-consensus/abci/client/mocks"
|
|
"git.cw.tr/mukan-network/mukan-consensus/proxy/mocks"
|
|
)
|
|
|
|
func TestAppConns_Start_Stop(t *testing.T) {
|
|
quitCh := make(<-chan struct{})
|
|
|
|
clientCreatorMock := &mocks.ClientCreator{}
|
|
|
|
clientMock := &abcimocks.Client{}
|
|
clientMock.On("SetLogger", mock.Anything).Return().Times(4)
|
|
clientMock.On("Start").Return(nil).Times(4)
|
|
clientMock.On("Stop").Return(nil).Times(4)
|
|
clientMock.On("Quit").Return(quitCh).Times(4)
|
|
|
|
clientCreatorMock.On("NewABCIClient").Return(clientMock, nil).Times(4)
|
|
|
|
appConns := NewAppConns(clientCreatorMock, NopMetrics())
|
|
|
|
err := appConns.Start()
|
|
require.NoError(t, err)
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
err = appConns.Stop()
|
|
require.NoError(t, err)
|
|
|
|
clientMock.AssertExpectations(t)
|
|
}
|
|
|
|
// Upon failure, we call cmtos.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{} = quitCh
|
|
|
|
clientCreatorMock := &mocks.ClientCreator{}
|
|
|
|
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()
|
|
|
|
clientCreatorMock.On("NewABCIClient").Return(clientMock, nil)
|
|
|
|
appConns := NewAppConns(clientCreatorMock, 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")
|
|
}
|
|
}
|