mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-02 23:15:36 +02:00
htlcswitch.test: add server error channel to concurrent access panic
This commit where added as a measure to avoid the panic during several server simultanoius fault. The panic happened becuase *t.Testing structure is not concurrent safe.
This commit is contained in:
committed by
Olaoluwa Osuntokun
parent
1eb906bcfb
commit
e170b43615
@@ -11,8 +11,6 @@ import (
|
||||
|
||||
"bytes"
|
||||
|
||||
"testing"
|
||||
|
||||
"github.com/btcsuite/fastsha256"
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
@@ -26,17 +24,16 @@ import (
|
||||
)
|
||||
|
||||
type mockServer struct {
|
||||
sync.Mutex
|
||||
|
||||
started int32
|
||||
shutdown int32
|
||||
wg sync.WaitGroup
|
||||
quit chan bool
|
||||
quit chan struct{}
|
||||
|
||||
t *testing.T
|
||||
name string
|
||||
messages chan lnwire.Message
|
||||
|
||||
errChan chan error
|
||||
|
||||
id [33]byte
|
||||
htlcSwitch *Switch
|
||||
|
||||
@@ -46,17 +43,17 @@ type mockServer struct {
|
||||
|
||||
var _ Peer = (*mockServer)(nil)
|
||||
|
||||
func newMockServer(t *testing.T, name string) *mockServer {
|
||||
func newMockServer(name string, errChan chan error) *mockServer {
|
||||
var id [33]byte
|
||||
h := sha256.Sum256([]byte(name))
|
||||
copy(id[:], h[:])
|
||||
|
||||
return &mockServer{
|
||||
t: t,
|
||||
errChan: errChan,
|
||||
id: id,
|
||||
name: name,
|
||||
messages: make(chan lnwire.Message, 3000),
|
||||
quit: make(chan bool),
|
||||
quit: make(chan struct{}),
|
||||
registry: newMockRegistry(),
|
||||
htlcSwitch: New(Config{}),
|
||||
interceptorFuncs: make([]messageInterceptor, 0),
|
||||
@@ -94,9 +91,7 @@ func (s *mockServer) Start() error {
|
||||
}
|
||||
|
||||
if err := s.readHandler(msg); err != nil {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
s.t.Fatalf("%v server error: %v", s.name, err)
|
||||
s.errChan <- errors.Errorf("%v server error: %v", s.name, err)
|
||||
}
|
||||
case <-s.quit:
|
||||
return
|
||||
@@ -329,7 +324,8 @@ func (s *mockServer) Disconnect(reason error) {
|
||||
fmt.Printf("server %v disconnected due to %v\n", s.name, reason)
|
||||
|
||||
s.Stop()
|
||||
s.t.Fatalf("server %v was disconnected", s.name)
|
||||
s.errChan <- errors.Errorf("server %v was disconnected: %v", s.name,
|
||||
reason)
|
||||
}
|
||||
|
||||
func (s *mockServer) WipeChannel(*lnwallet.LightningChannel) error {
|
||||
|
Reference in New Issue
Block a user