Browse Source

add channels to tests using Listen in a thread to sync; add some cleanup to other tests; fix a potential NPE

pull/166/head
Dan Ballard 1 year ago
parent
commit
6f6fa90946
4 changed files with 15 additions and 5 deletions
  1. +3
    -1
      peer/connections/peerpeerconnection.go
  2. +5
    -2
      peer/connections/peerpeerconnection_test.go
  3. +5
    -2
      peer/connections/peerserverconnection_test.go
  4. +2
    -0
      peer/cwtch_peer_test.go

+ 3
- 1
peer/connections/peerpeerconnection.go View File

@@ -150,5 +150,7 @@ func (ppc *PeerPeerConnection) Run() error {
// Close closes the connection
func (ppc *PeerPeerConnection) Close() {
ppc.state = KILLED
ppc.connection.Conn.Close()
if ppc.connection != nil {
ppc.connection.Conn.Close()
}
}

+ 5
- 2
peer/connections/peerpeerconnection_test.go View File

@@ -22,8 +22,9 @@ func PeerAuthValid(hostname string, key ed25519.PublicKey) (allowed, known bool)
return true, true
}

func runtestpeer(t *testing.T, tp *TestPeer, identity identity.Identity) {
func runtestpeer(t *testing.T, tp *TestPeer, identity identity.Identity, listenChan chan bool) {
ln, _ := net.Listen("tcp", "127.0.0.1:5452")
listenChan <- true
conn, _ := ln.Accept()
defer conn.Close()

@@ -65,7 +66,9 @@ func TestPeerPeerConnection(t *testing.T) {

tp := new(TestPeer)
tp.Init()
go runtestpeer(t, tp, identity)
listenChan := make(chan bool)
go runtestpeer(t, tp, identity, listenChan)
<-listenChan
state := ppc.GetState()
if state != DISCONNECTED {
fmt.Println("ERROR state should be disconnected")


+ 5
- 2
peer/connections/peerserverconnection_test.go View File

@@ -33,8 +33,9 @@ func (ts *TestServer) HandleFetchRequest() []*protocol.GroupMessage {
return []*protocol.GroupMessage{{Ciphertext: []byte("hello"), Signature: []byte{}, Spamguard: []byte{}}, {Ciphertext: []byte("hello"), Signature: []byte{}, Spamguard: []byte{}}}
}

func runtestserver(t *testing.T, ts *TestServer, identity identity.Identity) {
func runtestserver(t *testing.T, ts *TestServer, identity identity.Identity, listenChan chan bool) {
ln, _ := net.Listen("tcp", "127.0.0.1:5451")
listenChan <- true
conn, _ := ln.Accept()
defer conn.Close()

@@ -70,7 +71,9 @@ func TestPeerServerConnection(t *testing.T) {

ts := new(TestServer)
ts.Init()
go runtestserver(t, ts, identity)
listenChan := make(chan bool)
go runtestserver(t, ts, identity, listenChan)
<-listenChan
onionAddr := identity.Hostname()

psc := NewPeerServerConnection(connectivity.LocalProvider(), "127.0.0.1:5451|"+onionAddr)


+ 2
- 0
peer/cwtch_peer_test.go View File

@@ -23,8 +23,10 @@ func TestTrustPeer(t *testing.T) {
groupName := "2c3kmoobnyghj2zw6pwv7d57yzld753auo3ugauezzpvfak3ahc4bdyd"
alice := NewCwtchPeer("alice")
alice.Init(connectivity.LocalProvider())
defer alice.Shutdown()
bob := NewCwtchPeer("bob")
bob.Init(connectivity.LocalProvider())
defer bob.Shutdown()

bobOnion := bob.GetProfile().Onion
aliceOnion := alice.GetProfile().Onion


Loading…
Cancel
Save