diff --git a/testing/file_sharing_integration_test.go b/testing/file_sharing/file_sharing_integration_test.go similarity index 81% rename from testing/file_sharing_integration_test.go rename to testing/file_sharing/file_sharing_integration_test.go index 5d9e1d3..aca0473 100644 --- a/testing/file_sharing_integration_test.go +++ b/testing/file_sharing/file_sharing_integration_test.go @@ -1,4 +1,4 @@ -package testing +package file_sharing import ( "crypto/rand" @@ -7,6 +7,9 @@ import ( "cwtch.im/cwtch/event" "cwtch.im/cwtch/functionality/filesharing" "cwtch.im/cwtch/model" + "cwtch.im/cwtch/model/attr" + "cwtch.im/cwtch/peer" + "cwtch.im/cwtch/protocol/connections" "cwtch.im/cwtch/protocol/files" "encoding/base64" "encoding/hex" @@ -24,6 +27,29 @@ import ( "time" ) +func waitForPeerPeerConnection(t *testing.T, peera peer.CwtchPeer, peerb peer.CwtchPeer) { + for { + state, ok := peera.GetPeerState(peerb.GetOnion()) + if ok { + //log.Infof("Waiting for Peer %v to peer with peer: %v - state: %v\n", peera.GetProfile().Name, peerb.GetProfile().Name, state) + if state == connections.FAILED { + t.Fatalf("%v could not connect to %v", peera.GetOnion(), peerb.GetOnion()) + } + if state != connections.AUTHENTICATED { + fmt.Printf("peer %v waiting connect to peer %v, currently: %v\n", peera.GetOnion(), peerb.GetOnion(), connections.ConnectionStateName[state]) + time.Sleep(time.Second * 5) + continue + } else { + peerAName, _ := peera.GetAttribute(attr.GetLocalScope("name")) + peerBName, _ := peerb.GetAttribute(attr.GetLocalScope("name")) + fmt.Printf("%v CONNECTED and AUTHED to %v\n", peerAName, peerBName) + break + } + } + } + return +} + func TestFileSharing(t *testing.T) { numGoRoutinesStart := runtime.NumGoroutine()