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