Merge branch 'testfix' of cwtch.im/cwtch into master

This commit is contained in:
Dan Ballard 2019-07-15 13:28:53 -07:00 committed by Gogs
commit 7cdb73d04e
1 changed files with 8 additions and 11 deletions

View File

@ -23,11 +23,11 @@ func ServerAuthValid(hostname string, key ed25519.PublicKey) (allowed, known boo
type TestServer struct {
connection.AutoConnectionHandler
Received bool
Received chan bool
}
func (ts *TestServer) HandleGroupMessage(gm *protocol.GroupMessage) {
ts.Received = true
ts.Received<-true
}
func (ts *TestServer) HandleFetchRequest() []*protocol.GroupMessage {
@ -69,8 +69,10 @@ func TestPeerServerConnection(t *testing.T) {
identity := identity.InitializeV3("", &priv, &pub)
t.Logf("Launching Server....\n")
ts := new(TestServer)
ts.Init()
ts.Received = make(chan bool)
listenChan := make(chan bool)
go runtestserver(t, ts, identity, listenChan)
<-listenChan
@ -94,18 +96,13 @@ func TestPeerServerConnection(t *testing.T) {
}
time.Sleep(time.Second * 1)
go psc.Run()
time.Sleep(time.Second * 2)
state = psc.GetState()
if state != AUTHENTICATED {
t.Errorf("connection should now be authed(%v), instead was %v", AUTHENTICATED, state)
}
psc.WaitTilAuthenticated()
gm := &protocol.GroupMessage{Ciphertext: []byte("hello"), Signature: []byte{}}
psc.SendGroupMessage(gm)
time.Sleep(time.Second * 2)
if ts.Received == false {
t.Errorf("Should have received a group message in test server")
}
// Wait until message is received
<-ts.Received
if numcalls != 2 {
t.Errorf("Should have received 2 calls from fetch request, instead received %v", numcalls)