forked from cwtch.im/cwtch
add channels to tests using Listen in a thread to sync; add some cleanup to other tests; fix a potential NPE
This commit is contained in:
parent
60fb12054a
commit
6f6fa90946
|
@ -150,5 +150,7 @@ func (ppc *PeerPeerConnection) Run() error {
|
|||
// Close closes the connection
|
||||
func (ppc *PeerPeerConnection) Close() {
|
||||
ppc.state = KILLED
|
||||
if ppc.connection != nil {
|
||||
ppc.connection.Conn.Close()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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…
Reference in New Issue