discoverymgr_test.go : enhancement discovery 99/204599/1
authorjaehoon.hyun <jaehoon.hyun@samsung.com>
Thu, 25 Apr 2019 00:58:55 +0000 (09:58 +0900)
committerjaehoon.hyun <jaehoon.hyun@samsung.com>
Thu, 25 Apr 2019 00:58:55 +0000 (09:58 +0900)
Add waitServer function

Change-Id: I33e7f3a3fac515417b346d5ca102d3bcf1f0fb5f

src/discoverymgr/discovery_execution.go
src/discoverymgr/discoverymgr_test.go

index dfc4b504b5a1b3547ae527ef1fbce0869e082c6e..033a7fa04370cc7a83bfdf4dd149fc081ecf01a9 100755 (executable)
  * limitations under the License.
  *
  *******************************************************************************/
-package discoverymgr
+
+/*
+NOTE : systemctl stop edge-orchestration.service
+*/
+ package discoverymgr
 
 import (
        "context"
@@ -25,6 +29,7 @@ import (
        "grandcat/zeroconf"
 )
 
+
 //GetDeviceList return device list
 func GetDeviceList() ([]DeviceReturnInfo, error) {
 
@@ -32,17 +37,7 @@ func GetDeviceList() ([]DeviceReturnInfo, error) {
                return nil, err
        }
 
-       //NOTE :
-       //it can be happend, pollingOutbound function is out,
-       //but gServer is not initialized because InitDiscovery go routine
-       for {
-               if IsNilServer() == true {
-                       time.Sleep(0)
-               } else {
-                       break
-               }
-       }
-
+       waitServer()
        gServer.IsInterfaceChange()
 
        zeroconf.MapMTX.Lock()
@@ -65,16 +60,7 @@ func GetDeviceListWithService(target string) ([]string, error) {
                return nil, err
        }
 
-       //NOTE :
-       //it can be happend, pollingOutbound function is out,
-       //but gServer is not initialized because InitDiscovery go routine
-       for {
-               if IsNilServer() == true {
-                       time.Sleep(0)
-               } else {
-                       break
-               }
-       }
+       waitServer()
 
        gServer.IsInterfaceChange()
 
@@ -90,6 +76,7 @@ func GetDeviceListWithService(target string) ([]string, error) {
                }
        }
 
+       log.Println("GetDeviceListWithService", ret)
        return ret, nil
 }
 
@@ -123,6 +110,19 @@ func discoveryBGR() {
        }
 }
 
+func waitServer() {
+       //NOTE :
+       //it can be happend, pollingOutbound function is out,
+       //but gServer is not initialized because InitDiscovery go routine
+       for {
+               if IsNilServer() == true {
+                       time.Sleep(0)
+               } else {
+                       break
+               }
+       }
+}
+
 func discoverDevice(t int) (map[string][]string, error) {
 
        domain := "local"
index 1748c6fa29879fb6e7fda241a43f8ac49837d6c7..aa06c954447fc4764bf5b63a72cd39842be3c08c 100755 (executable)
@@ -30,12 +30,14 @@ func closeDiscovery() {
 }
 func TestGetDeviceListWithService(t *testing.T) {
        err := InitDiscovery()
+       waitServer()
        if err != nil {
                t.Fatal()
        }
        doc := new(confdescription.Doc)
        doc.ServiceInfo.ServiceName = "test1"
        err = AddNewServiceName(doc)
+
        time.Sleep(7 * time.Second)
        if err != nil {
                closeDiscovery()