diff --git a/app/plugins/contactRetry.go b/app/plugins/contactRetry.go index 249c3dd..67de66e 100644 --- a/app/plugins/contactRetry.go +++ b/app/plugins/contactRetry.go @@ -259,6 +259,7 @@ func (cr *contactRetry) run() { cr.addConnection(server, connections.DISCONNECTED, serverConn, lastSeen) } // this was an authorized event, and so we store this peer. + log.Debugf("authorizing id: %v", id); cr.authorizedPeers.Store(id, true) if c, ok := cr.connections.Load(id); ok { contact := c.(*contact) diff --git a/app/plugins/contactRetry_test.go b/app/plugins/contactRetry_test.go index adf2604..54a8052 100644 --- a/app/plugins/contactRetry_test.go +++ b/app/plugins/contactRetry_test.go @@ -23,32 +23,37 @@ func TestContactRetryQueue(t *testing.T) { cr.protocolEngine = true // fake protocol engine go cr.run() + testOnion := "2wgvbza2mbuc72a4u6r6k4hc2blcvrmk4q26bfvlwbqxv2yq5k52fcqd" + t.Logf("contact plugin up and running..sending peer connection...") // Assert that there is a peer connection identified as "test" - bus.Publish(event.NewEvent(event.QueuePeerRequest, map[event.Field]string{event.RemotePeer: "test", event.LastSeen: "test"})) + bus.Publish(event.NewEvent(event.QueuePeerRequest, map[event.Field]string{event.RemotePeer: testOnion, event.LastSeen: "test"})) // Wait until the test actually exists, and is queued // This is the worst part of this test setup. Ideally we would sleep, or some other yielding, but // go test scheduling doesn't like that and even sleeping long periods won't cause the event thread to make // progress... for { - if pinf, exists := cr.connections.Load("test"); exists { + if pinf, exists := cr.connections.Load(testOnion); exists { if pinf.(*contact).queued { - break + if _,exists := cr.authorizedPeers.Load(testOnion); exists { + t.Logf("authorized"); + break; + } } } } - pinf, _ := cr.connections.Load("test") + pinf, _ := cr.connections.Load(testOnion) if pinf.(*contact).queued == false { t.Fatalf("test connection should be queued, actually: %v", pinf.(*contact).queued) } // Asset that "test" is authenticated - cr.handleEvent("test", connections.AUTHENTICATED, peerConn) + cr.handleEvent(testOnion, connections.AUTHENTICATED, peerConn) // Assert that "test has a valid state" - pinf, _ = cr.connections.Load("test") + pinf, _ = cr.connections.Load(testOnion) if pinf.(*contact).state != 3 { t.Fatalf("test connection should be in authenticated after update, actually: %v", pinf.(*contact).state) } @@ -62,11 +67,11 @@ func TestContactRetryQueue(t *testing.T) { } // Publish a new peer request... - bus.Publish(event.NewEvent(event.QueuePeerRequest, map[event.Field]string{event.RemotePeer: "test"})) + bus.Publish(event.NewEvent(event.QueuePeerRequest, map[event.Field]string{event.RemotePeer: testOnion})) time.Sleep(time.Second) // yield for a second so the event can catch up... // Peer test should be forced to queue.... - pinf, _ = cr.connections.Load("test") + pinf, _ = cr.connections.Load(testOnion) if pinf.(*contact).queued != true { t.Fatalf("test connection should be forced to queue after new queue peer request") }