intel / iotivity-node

Node.js bindings for IoTivity
https://www.iotivity.org/
42 stars 44 forks source link

De-dupe discovered devices/resources #69

Closed wanghongjuan closed 8 years ago

wanghongjuan commented 8 years ago

Some asserts of the test API Presence are failed on recent GT images(from build#157 to build#164), but they are passed on build#154. We checked the iotivity-node source code version is 1.1.0-4-r0 in image from build#157.

The test steps:

  1. Enter the test device and get the source code by command: git clone https://github.com/otcshare/iotivity-node.git
  2. Copy some necessary files to "/usr/lib/node_modules/iotivity-node" File list:Gruntfiles.js, .jscsrc, grunt-build and tests
  3. Install the node modules that defined in file "package.json" and "grunt-cli" cd /usr/lib/node_modules/iotivity-node; npm install; npm install grunt-cli
  4. Run a single test via below command: ./node_modules/grunt-cli/bin/grunt test --suites="API Presence"

    Test Environment:

Tuchuck with build#157(using the image named like: ostro-xt-image-noswupd-benchmark-qa-intel-corei7-64-2016-07-25_07-09-15-build-157.dsk.xz ). Failure log:

root@intel-corei7-64:/usr/lib/node_modules/iotivity-node# ./node_modules/grunt-cli/bin/grunt test --suites="API Presence"
Running "jshint:nonlib" (jshint) task
>> 65 files lint free.

Running "jshint:lib" (jshint) task
>> 8 files lint free.

Running "jscs:js" (jscs) task
>> 73 files without code style errors.

Running "testsuite" task

API Presence
✓ @       964: Server 1: device configured successfully
✓ @       994: Server 1: device.register() successful
✓ @      1403: Server 2: device configured successfully
✓ @      1405: Server 2: device.register() successful
✓ @      2778: subscribe has defined
✓ @      2782: subscribe is a function
✓ @      2784: unsubscribe has defined
✓ @      2786: unsubscribe is a function
✓ @      2788: ondevicechange has defined
✓ @      3331: Server 1: disablePresence()
✓ @      3367: Server 2: disablePresence()
✓ @      6539: Client: No events upon disablePresence() while not subscribed
✓ @      6977: Server 1: enablePresence()
✓ @      7026: Server 2: enablePresence()
✗ @     10194: Client: No events upon enablePresence() while not subscribed
Actual:
[
  [
    "{\"event\":\"resourcefound\",\"source\":{\"path\":\"/a/e6d68f66-6f4e-4ff1-8fef-5459062d8375\",\"deviceId\":\"36376632-3338-3064-2d31-3165632d3462\"}}",
    "{\"event\":\"resourcefound\",\"source\":{\"path\":\"/a/e6d68f66-6f4e-4ff1-8fef-5459062d8375\",\"deviceId\":\"36376632-3338-3064-2d31-3165632d3462\"}}"
  ],
  [
    "{\"event\":\"resourcefound\",\"source\":{\"path\":\"/a/e6d68f66-6f4e-4ff1-8fef-5459062d8375\",\"deviceId\":\"36643233-3566-3531-2d35-3539612d3462\"}}",
    "{\"event\":\"resourcefound\",\"source\":{\"path\":\"/a/e6d68f66-6f4e-4ff1-8fef-5459062d8375\",\"deviceId\":\"36643233-3566-3531-2d35-3539612d3462\"}}"
  ]
]
Expected:
[
  [],
  []
]
✓ @     10733: Server 2: disablePresence()
✓ @     14632: Server 1: disablePresence()
✓ @     14636: Client: Events upon disablePresence() of both servers while subscribed are as expected
✓ @     14984: Server 2: enablePresence()
✓ @     15132: Server 1: enablePresence()
✗ @     18040: Client: Events upon enablePresence() of both servers while subscribed are as expected
Actual:
[
  [
    "{\"event\":\"devicechange\",\"changeType\":\"added\",\"source\":{\"deviceId\":\"36376632-3338-3064-2d31-3165632d3462\"}}",
    "{\"event\":\"devicefound\",\"source\":{\"deviceId\":\"36376632-3338-3064-2d31-3165632d3462\"}}",
    "{\"event\":\"resourcefound\",\"source\":{\"path\":\"/a/e6d68f66-6f4e-4ff1-8fef-5459062d8375\",\"deviceId\":\"36376632-3338-3064-2d31-3165632d3462\"}}",
    "{\"event\":\"resourcefound\",\"source\":{\"path\":\"/a/e6d68f66-6f4e-4ff1-8fef-5459062d8375\",\"deviceId\":\"36376632-3338-3064-2d31-3165632d3462\"}}",
    "{\"event\":\"resourcefound\",\"source\":{\"path\":\"/a/e6d68f66-6f4e-4ff1-8fef-5459062d8375\",\"deviceId\":\"36376632-3338-3064-2d31-3165632d3462\"}}"
  ],
  [
    "{\"event\":\"devicechange\",\"changeType\":\"added\",\"source\":{\"deviceId\":\"36643233-3566-3531-2d35-3539612d3462\"}}",
    "{\"event\":\"devicefound\",\"source\":{\"deviceId\":\"36643233-3566-3531-2d35-3539612d3462\"}}",
    "{\"event\":\"resourcefound\",\"source\":{\"path\":\"/a/e6d68f66-6f4e-4ff1-8fef-5459062d8375\",\"deviceId\":\"36643233-3566-3531-2d35-3539612d3462\"}}",
    "{\"event\":\"resourcefound\",\"source\":{\"path\":\"/a/e6d68f66-6f4e-4ff1-8fef-5459062d8375\",\"deviceId\":\"36643233-3566-3531-2d35-3539612d3462\"}}",
    "{\"event\":\"resourcefound\",\"source\":{\"path\":\"/a/e6d68f66-6f4e-4ff1-8fef-5459062d8375\",\"deviceId\":\"36643233-3566-3531-2d35-3539612d3462\"}}"
  ]
]
Expected:
[
  [
    "{\"event\":\"devicechange\",\"changeType\":\"added\",\"source\":{\"deviceId\":\"36376632-3338-3064-2d31-3165632d3462\"}}",
    "{\"event\":\"devicefound\",\"source\":{\"deviceId\":\"36376632-3338-3064-2d31-3165632d3462\"}}",
    "{\"event\":\"resourcefound\",\"source\":{\"path\":\"/a/e6d68f66-6f4e-4ff1-8fef-5459062d8375\",\"deviceId\":\"36376632-3338-3064-2d31-3165632d3462\"}}"
  ],
  [
    "{\"event\":\"devicechange\",\"changeType\":\"added\",\"source\":{\"deviceId\":\"36643233-3566-3531-2d35-3539612d3462\"}}",
    "{\"event\":\"devicefound\",\"source\":{\"deviceId\":\"36643233-3566-3531-2d35-3539612d3462\"}}",
    "{\"event\":\"resourcefound\",\"source\":{\"path\":\"/a/e6d68f66-6f4e-4ff1-8fef-5459062d8375\",\"deviceId\":\"36643233-3566-3531-2d35-3539612d3462\"}}"
  ]
]
✓ @     18505: Server 2: disablePresence()
✓ @     18584: Server 1: disablePresence()
✓ @     21719: Client: Events upon disablePresence() with one server not subscribed are as expected
✓ @     22237: Server 2: enablePresence()
✓ @     22306: Server 1: enablePresence()
✗ @     25465: Client: Events upon enablePresence() with one server not subscribed are as expected
Actual:
[
  [
    "{\"event\":\"resourcefound\",\"source\":{\"path\":\"/a/e6d68f66-6f4e-4ff1-8fef-5459062d8375\",\"deviceId\":\"36376632-3338-3064-2d31-3165632d3462\"}}",
    "{\"event\":\"resourcefound\",\"source\":{\"path\":\"/a/e6d68f66-6f4e-4ff1-8fef-5459062d8375\",\"deviceId\":\"36376632-3338-3064-2d31-3165632d3462\"}}"
  ],
  [
    "{\"event\":\"devicechange\",\"changeType\":\"added\",\"source\":{\"deviceId\":\"36643233-3566-3531-2d35-3539612d3462\"}}",
    "{\"event\":\"devicefound\",\"source\":{\"deviceId\":\"36643233-3566-3531-2d35-3539612d3462\"}}",
    "{\"event\":\"resourcefound\",\"source\":{\"path\":\"/a/e6d68f66-6f4e-4ff1-8fef-5459062d8375\",\"deviceId\":\"36643233-3566-3531-2d35-3539612d3462\"}}",
    "{\"event\":\"resourcefound\",\"source\":{\"path\":\"/a/e6d68f66-6f4e-4ff1-8fef-5459062d8375\",\"deviceId\":\"36643233-3566-3531-2d35-3539612d3462\"}}",
    "{\"event\":\"resourcefound\",\"source\":{\"path\":\"/a/e6d68f66-6f4e-4ff1-8fef-5459062d8375\",\"deviceId\":\"36643233-3566-3531-2d35-3539612d3462\"}}"
  ]
]
Expected:
[
  [],
  [
    "{\"event\":\"devicechange\",\"changeType\":\"added\",\"source\":{\"deviceId\":\"36643233-3566-3531-2d35-3539612d3462\"}}",
    "{\"event\":\"devicefound\",\"source\":{\"deviceId\":\"36643233-3566-3531-2d35-3539612d3462\"}}",
    "{\"event\":\"resourcefound\",\"source\":{\"path\":\"/a/e6d68f66-6f4e-4ff1-8fef-5459062d8375\",\"deviceId\":\"36643233-3566-3531-2d35-3539612d3462\"}}"
  ]
]
✓ @     25902: Server 2: device.unregister() successful
✓ @     25919: Server 1 exited successfully (0)
✓ @     26277: Server 1 did not segfault
✓ @     26542: Server 1 exited successfully (0)
✓ @     26548: Server 1 did not segfault
✓ @     26551: Client exited successfully (0)
✓ @     26553: Client did not segfault
✓ @     26562: Server 1: device.unregister() successful
Total assertions: ( 32 + 3 ) / 35
Warning: Task "testsuite" failed. Use --force to continue.

Aborted due to warnings.
root@intel-corei7-64:/usr/lib/node_modules/iotivity-node#
ibelem commented 8 years ago

Update: Dev will not fix this right now, will define the APIs and implement them

gabrielschulhof commented 8 years ago

Actually, I just realized the root cause. It requires the followings:

  1. The client and the server are running on the same machine.
  2. The machine on which they are running has multiple network interfaces.

In this case, devices and resources will be discovered multiple times, resulting in duplicate events.

Thus, if you leave a total of one interface up on the test device, this error will go away.

Still, I believe this should be fixed in the higher-level API implementation, and it can be fixed, but we must be able to compare discovery handles.

gabrielschulhof commented 8 years ago

I think I'll change the test to de-dupe the incoming events, unless we decide that we wish to address this corner case in the implementation.

wanghongjuan commented 8 years ago

Hi, @gabrielschulhof this issue doesn't reproduced on Joule 570x with image#191, but it is still exists on Galileo with image#508 and Joule with image#190. It is confused me, because the iotivity-node version is 1.1.0-4 on image#190/191, so I compare the difference between image#190 and image#191, there is a new commit d216381 added into image#191, could you help to confirm this issue whether is relevant with the commit? If no, why this issue doesn't reproduced on image#191?