fix test back by making sure channels are listening before sending. otherwise contexts won't switch in 1-core system.
@@ -74,13 +74,10 @@ func TestNet_EnqueueMessage(t *testing.T) {
}
func TestHandlePreSessionIncomingMessage(t *testing.T) {
- cfg := config.DefaultConfig()
- cfg.NodeID = ""
- cfg.NewNode = true
var wg sync.WaitGroup
- localNode, _ := node.GenerateTestNodeWithConfig(t, cfg)
- remoteNode, _ := node.GenerateTestNodeWithConfig(t, cfg)
+ localNode, _ := node.GenerateTestNode(t)
+ remoteNode, _ := node.GenerateTestNode(t)
con := NewConnectionMock(localNode.PublicKey())
con.addr = localNode.Address()
@@ -92,38 +89,39 @@ func TestHandlePreSessionIncomingMessage(t *testing.T) {
assert.NoError(t, err, "cannot marshal obj")
wg.Add(1)
go func() {
- waitForCallbackOrTimeout(t, outchan, session)
wg.Done()
+ waitForCallbackOrTimeout(t, outchan, session)
}()
+
+ wg.Wait()
err = remoteNet.HandlePreSessionIncomingMessage(con, data)
assert.NoError(t, err, "handle session failed")
- wg.Wait()
assert.Equal(t, int32(1), con.SendCount())
con.remotePub = nil
- wg.Add(1)
+ wg.Add(1)
go func() {
- waitForCallbackOrTimeout(t, outchan, session)
wg.Done()
+ waitForCallbackOrTimeout(t, outchan, session)
}()
+ wg.Wait()
err = remoteNet.HandlePreSessionIncomingMessage(con, data)
assert.NoError(t, err, "handle session failed")
- wg.Wait()
assert.Equal(t, localNode.PublicKey().String(), con.remotePub.String(), "Remote connection was not updated properly")
othercon := NewConnectionMock(remoteNode.PublicKey())
othercon.addr = remoteNode.Address()
othercon.SetSendResult(fmt.Errorf("error or whatever"))
+ wg.Add(1)
go func() {
- waitForCallbackOrTimeout(t, outchan, nil)
wg.Done()
+ waitForCallbackOrTimeout(t, outchan, nil)
}()
- wg.Add(1)
+ wg.Wait()
err = remoteNet.HandlePreSessionIncomingMessage(othercon, data)
assert.Error(t, err, "handle session failed")
- wg.Wait()
assert.Nil(t, othercon.Session())
out.NetworkID = out.NetworkID + 1
